0

I'm trying to use the @BlobInput annotation in a Java Azure Function and the argument that i'm annotating does not get populated with the content of the blob i'm referencing.

I believe it might have something to do with the "name" field of the BlobInput, but i'm a little unclear on what that's supposed to be populated with. According to the documentation here, it should be

The name of the variable that represents the blob in function code

But I'm very unclear on what exactly that means. Is there something i should be putting in my local.settings.json to get this thing to run the way i'm expecting it to?

g4tZby
  • 1

1 Answers1

0

Just the meaning it shows, cause there is not function.json file when you write your java azure function code, and after function compiled it depends the function.json file to get the input details. More details about function.json refer to here: Function code.

After your java function compiled, you could follow this Folder structure to get the function.json file, then you will find the @BlobInput binding name will be the blob input binding name.

Below is my test code, get blob content with @BlobInput binding.

public HttpResponseMessage  run(
             @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context,
             @BlobInput(
                     name = "file",
                     dataType = "binary",
                     path = "test/abc1.txt",connection = "AzureWebJobsStorage")
                     byte[] content) {
        context.getLogger().info("Java HTTP trigger processed a request.");


        String str = new String(content);
        context.getLogger().info(str);
        return request.createResponseBuilder(HttpStatus.OK)
                .body("The size is: " + content.length + " bytes")
                .build();


    }

And here is my function.json file binding, you could see here name is file.

"bindings" : [ {
    "type" : "httpTrigger",
    "direction" : "in",
    "name" : "req",
    "methods" : [ "GET", "POST" ],
    "authLevel" : "ANONYMOUS"
  }, {
    "type" : "blob",
    "direction" : "in",
    "name" : "file",
    "path" : "test/abc1.txt",
    "dataType" : "binary",
    "connection" : "AzureWebJobsStorage"
  }, {
    "type" : "http",
    "direction" : "out",
    "name" : "$return"
  } ]

And below is my test result, log the file content, and send a response. If you still have errors, please share your code to let me have a test. Hope this could help you.

enter image description here

George Chen
  • 13,703
  • 2
  • 11
  • 26
  • This might be a dumb question, but when running locally, local.settings.json takes the place of function.json, right? so i'd want to throw the bindings in there? – g4tZby Apr 30 '20 at 17:45
  • No, local.settings.json acts as application settings, you need to bind the binding in the code, after compiled function core tool will generate the function.json file. – George Chen May 01 '20 at 01:21
  • And if this could help you, you could accept it as the answer. – George Chen May 01 '20 at 01:21