0

I have a HttpTrigger function with request body as

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

I want to get the Id from request body into @BlobOuput path like below

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

Is there any way to achieve this functionality.

Usman Ali
  • 58
  • 4
  • Do you have any other concerns? if you have no other concern, could you please accept it as answer? – Jim Xu Apr 08 '20 at 05:46

1 Answers1

1

Regarding how to read @BlobOuput path from httptrigger request body, please refer to the following steps.

I use the following request body for test

{
"BlobName":"test.txt",
 "Content":"test"
}
  1. Create a custom class as the request body.
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;
    }
}
  1. Function code
@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();

    }
  1. Test
POST <function url>
Content-Type:application/json

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

enter image description here enter image description here

Jim Xu
  • 21,610
  • 2
  • 19
  • 39