我有一个带有请求正文的HttpTrigger函数,

{
"id":"222",
"name":"some name"
}


我想从请求正文中获取ID到如下所示的@BlobOuput路径中

@BlobOutput(name="blob",  path="input-blob/{body.id}")


有什么方法可以实现此功能。

最佳答案

关于如何从httptrigger请求正文读取@BlobOuput路径,请参考以下步骤。

我使用以下请求正文进行测试

{
"BlobName":"test.txt",
 "Content":"test"
}



创建一个自定义类作为请求主体。


public class BlobInfo {
    public String Content;
    public String BlobName;

    public String getContent() {
        return Content;
    }

    public void setContent(String content) {
        Content = content;
    }

    public String getBlobName() {
        return BlobName;
    }

    public void setBlobName(String blobName) {
        BlobName = blobName;
    }
}



功能码


@FunctionName("HttpExample")
    public HttpResponseMessage run(
            @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<BlobInfo>> request, // request body gets automatically de-serialized into the custom object you create
            @BlobOutput(name="output",  path = "test/{BlobName}" //  use the custom object's property you need as file name
                    ,connection = "AzureWebJobsStorage") OutputBinding<String> outputItem,
            final ExecutionContext context) throws IOException {
        context.getLogger().info("Java HTTP trigger processed a request.");
        BlobInfo body = request.getBody().get();
        context.getLogger().info(body.Content);
        context.getLogger().info(body.BlobName);
        outputItem.setValue("Hello World!");

        return request.createResponseBuilder(HttpStatus.OK).body("success").build();

    }



测试


POST <function url>
Content-Type:application/json

{
 "BlobName":"test.txt",
 "Content":"test"
}


java - Azure Java函数,在BlobOutput路径批注中获取HttpTrigger主体属性值-LMLPHP
java - Azure Java函数,在BlobOutput路径批注中获取HttpTrigger主体属性值-LMLPHP

08-16 01:54