Azure Java函数,获取BlobOutput路径注释中的HttpTrigger body属性值

Azure Java函数,获取BlobOutput路径注释中的HttpTrigger body属性值,java,azure,function,dynamic-binding,Java,Azure,Function,Dynamic Binding,我有一个HttpTrigger函数,请求主体为 { "id":"222", "name":"some name" } 我想将Id从请求主体获取到@BlobOuput路径中,如下所示 @BlobOutput(name="blob", path="input-blob/{body.id}") 是否有任何方法可以实现此功能。关于如何从httptrigger请求正文读取@BlobOuput路径,请参考以下步骤 我使用以下请求主体进行测试 { "BlobName":"test.txt", "Con

我有一个HttpTrigger函数,请求主体为

{
"id":"222",
"name":"some name"
}
我想将Id从请求主体获取到@BlobOuput路径中,如下所示

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

是否有任何方法可以实现此功能。

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

我使用以下请求主体进行测试

{
"BlobName":"test.txt",
 "Content":"test"
}
  • 创建一个自定义类作为请求主体
  • 功能代码
  • @FunctionName(“HttpExample”)
    公共HttpResponseMessage运行(
    @HttpTrigger(name=“req”,methods={HttpMethod.GET,HttpMethod.POST},authLevel=AuthorizationLevel.ANONYMOUS)HttpRequestMessage请求,//请求体自动反序列化到您创建的自定义对象中
    @BlobOutput(name=“output”,path=“test/{BlobName}”//使用所需的自定义对象属性作为文件名
    ,connection=“azurewebjobstorage”)输出绑定输出项,
    最终ExecutionContext)引发IOException{
    context.getLogger().info(“JavaHTTP触发器处理了一个请求。”);
    BlobInfo body=request.getBody().get();
    context.getLogger().info(body.Content);
    context.getLogger().info(body.BlobName);
    setValue(“你好,世界!”);
    返回request.createResponseBuilder(HttpStatus.OK).body(“success”).build();
    }
    
  • 试验
  • POST
    内容类型:application/json
    {
    “BlobName”:“test.txt”,
    “内容”:“测试”
    }
    

    您还有其他顾虑吗?如果你没有其他顾虑,请接受它作为回答好吗?
    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"
    }