title: Blob access from event grid azure function using Java API
body: <p><strong>Background</strong></p>
  
  <p>Java Azure functions 2, using blob storage with event grid subsription for blob create events which the function (see below) is bound to via the event trigger.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>Not clear how to <strong>bind a blob</strong> (See <code>@BlobInput</code> Java annotation) Input Blob Binding from Azure functions which the <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-java#binary-data" rel="nofollow noreferrer">documentation</a> illudes to, but not sure if possible in the Java API, unlike its C# counterpart. </p>
  
  <p>When the function is invocked nothing is bound to the <code>content</code> varaible using the <code>@BlobInput</code> annotation, so once the line is reached where the <code>content</code> variable is reached, it results in a null pointer.  </p>
  
  <p>The <code>path = "{data.url}"</code> based on documentation allows you to access event data passed to the function. The data passed from the event is all bound to the <code>EventSchema event</code> POJO also (see below for an example of an event).</p>
  
  <p>The <code>@StorageAccount("AzureWebJobsStorage")</code> links to the properties stored and setup by default via the functions configuration, which is correct.</p>
  
  <p><strong>Tried</strong></p>
  
  <p><em>Deployed azure function:</em> </p>
  
  <pre><code>@StorageAccount("AzureWebJobsStorage")
  @FunctionName("myfunc")
  public void run(@EventGridTrigger(name = "blobeventgrid") EventSchema event,
                  @BlobInput(name = "zipfile",dataType = "binary",path = "{data.url}") byte[] content,
                  final ExecutionContext context) {
      context.getLogger().info("Java Event Grid trigger function executed.");
      context.getLogger().info("Id: " + event.id);
      context.getLogger().info("Data: " + event.data);
      context.getLogger().info("zip file: " + content.length);
  }
  </code></pre>
  
  <p><em>Example Event Grid Event</em></p>
  
  <pre><code>{
    "topic": "/subscriptions/&lt;omitted&gt;/resourceGroups/java-functions-group/providers/Microsoft.Storage/storageAccounts/&lt;omitted storageaccount&gt;",
    "subject": "/blobServices/default/containers/mycontainer/blobs/compressed.zip",
    "eventType": "Microsoft.Storage.BlobCreated",
    "eventTime": "2019-10-02T12:46:33.2915427Z",
    "id": "&lt;omitted&gt;",
    "data": {
    "api": "PutBlob",
    "clientRequestId": "&lt;omitted&gt;",
    "requestId": "&lt;omitted&gt;",
    "eTag": "&lt;omitted&gt;",
    "contentType": "application/zip",
    "contentLength": 32460,
    "blobType": "BlockBlob",
    "url": "https://&lt;omitted storageaccount&gt;.blob.core.windows.net/mycontainer/compressed.zip",
    "sequencer": "&lt;omitted&gt;",
    "storageDiagnostics": {
    "batchId": "&lt;omitted&gt;"
      }
    },
    "dataVersion": "",
    "metadataVersion": "1"
  }
  </code></pre>
  
  <p><strong>Log from running function locally</strong> <em>(remote is same)</em></p>
  
  <pre><code>[10/05/2019 18:48:16] Executing HTTP request: {
  [10/05/2019 18:48:16]   "requestId": "299a3870-98cf-41cf-b418-7cdb33c1f1c7",
  [10/05/2019 18:48:16]   "method": "POST",
  [10/05/2019 18:48:16]   "uri": "/runtime/webhooks/EventGrid"
  [10/05/2019 18:48:16] }
  [10/05/2019 18:48:17] Executing 'Functions.myFunc' (Reason='EventGrid trigger fired at 2019-10-05T19:48:17.4343990+01:00', Id=82a2f47b-34bc-492f-8b60-12601beb45ee)
  [10/05/2019 18:48:18] Java Event Grid trigger function executed.
  [10/05/2019 18:48:18] Event content 
  [10/05/2019 18:48:18] Subject: /blobServices/default/containers/mycontainer/blobs/zip/compressed.zip
  [10/05/2019 18:48:18] Time: Mon Sep 30 20:46:33 BST 2019
  [10/05/2019 18:48:18] Id: 7de5edc4-c01e-0107-1bc7-77755f061e49
  [10/05/2019 18:48:18] Data: {api=PutBlob, clientRequestId=007dd554-e3bb-11e9-80b4-dca90473b192, requestId=7de5edc4-c01e-0107-1bc7-77755f000000, eTag=0x8D745DEE5936EE3, contentType=application/zip, contentLength=32460.0, blobType=BlockBlob, url=https://&lt;ommitted storage account&gt;.blob.core.windows.net/mycontainer/zip/compressed.zip, sequencer=000000000000000000000000000007E200000000002ab872, storageDiagnostics={batchId=1c15a3b6-2006-0046-00c7-771b19000000}}
  [10/05/2019 18:48:18] Executed 'Functions.myFunc' (Failed, Id=82a2f47b-34bc-492f-8b60-12601beb45ee)
  [10/05/2019 18:48:18] System.Private.CoreLib: Exception while executing function: Functions.myFunc. System.Private.CoreLib: Result: Failure
  [10/05/2019 18:48:18] Exception: NullPointerException: 
  </code></pre>
  
  <p>Falls over because of nothing is bound to content byte[]...</p>
  
  <p><strong>Alternative</strong></p>
  
  <p>Using the Azure Java SDK, but trying to stay with the semantics around Azure functions.</p>