0

I have a EventHubTriggered Function app.Here is the code sample of the method signature:

@FunctionName("foo") @StorageAccount("foostorageread") public HttpResponseMessage run( @HttpTrigger( name = "req", methods = {HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional> request, @BlobInput( name = "{test1}", dataType = "string", path = "blobStorageContainer/{test1}.json") String test1,

        @BlobInput(
                  name = "test2", 
                  dataType = "string", 
                  path = "blobStorageContainer/{test2}.json") String test2,
       
        final ExecutionContext context) 

I want to add the input binding to CloudBlobContainer(blobStorageContainer in the method signature above) in the method signature so that I do not need to explicitly connect to this container in my method (as I'll need to access more files from this container). Is there any annotations/ways I can do that in Java?

Jasmine
  • 135
  • 3
  • 16

2 Answers2

0

I followed the blog to connect the Blob Storage container to get files.

Please refer a below code to use the CloudBlobContainer to connect the container and create the new container if it not exist in a blob.

CloudStorageAccount storageAccountDest;
CloudBlobClient blobClientDest = null;
CloudBlobContainer containerDest = null;
String storageConnectionStringDest = System.getenv("AzureStorageDemoConnectionStringDest");

// Parse the connection string and create a blob client to interact with Blob
// storage
storageAccountDest = CloudStorageAccount.parse(storageConnectionStringDest);
blobClientDest = storageAccountDest.createCloudBlobClient();  
containerDest = blobClientDest.getContainerReference("files2");

// Create the container if it does not exist with public access.
context.getLogger().info("Creating container: " + containerDest.getName());
containerDest.createIfNotExists(BlobContainerPublicAccessType.CONTAINER, new BlobRequestOptions(),
new OperationContext());
CloudBlob blobDest = containerDest.getBlockBlobReference(filename);
try {
    context.getLogger().info("Start Uploading blob: " + filename);
    blobDest.uploadFromByteArray(content, 0, content.length);
    context.getLogger().info("Finished Uploading blob: " + filename);
} 
catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Please have a look here

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15
0

Binding is done on a single blob object not whole storage account/container. The reason is that the function expects a concrete blob object(as some bytes).

Eventually you can add multiple separate bindings and use binding expressions. This can work if you have a fixed set of filenames.