Azure-Samples / function-image-upload-resize

Sample function in Azure Functions that demonstrates how to upload and resize images in Azure Storage.
MIT License
67 stars 161 forks source link

Can not create blob storage binding in c# using visual studio 2017 #6

Open sbailey476 opened 6 years ago

sbailey476 commented 6 years ago

Trying to remake the this example in c# using visual studio but having issues making the azure function trigger be triggered by the event grid and bind to the blob storage.

Current Code:

using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs;
using Microsoft.WindowsAzure.Storage.Blob;

namespace FunctionApp
{
    public static class CreateIndex
    {
        [FunctionName("CreateIndex")]
        [StorageAccount("backup_STORAGE")]
        public static void Run(
            [EventGridTrigger()] EventGridEvent myEvent, 
            [Blob("{data.url}")] CloudBlockBlob inputBlob, 
            TraceWriter log)
        {
            log.Info(myEvent.ToString());
            log.Info(inputBlob.ToString());
        }
    }
}

Generated function.json:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.6",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "myEvent"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/FunctionApp.dll",
  "entryPoint": "FunctionApp.CreateIndex.Run"
}

The binding is working for the event grid trigger but not the Blob input.

SyntaxC4 commented 6 years ago

@ggailey777 Are you able to look into this?

ggailey777 commented 6 years ago

It looks like there seems to be a case sensitivity issue when using Event Grid with VS tooling, as mentioned here. Please verify that the case of the function name in your code matches with the full endpoint URL of the EG subscription in the portal.

yaprigal commented 6 years ago

I succeeded using the following code: [FunctionName("Function1")] public static void Run([EventGridTrigger]JObject eventGridEvent, [Blob("{data.url}", FileAccess.Read, Connection = "myblobconn")]Stream inputBlob, TraceWriter log)

yaprigal commented 6 years ago

I succeed using : "Newtonsoft.Json" Version="9.0.1"

MattFinlay commented 3 years ago

after looking through the stack exchange post linked above by @ggailey777 I got it working after changing the "Run" Function name to match what was inside the FunctionNameAttribute. This created a new function inside my FunctionApp, so i had to hook it up again. I also added Access Control Settings on my storage so that my function App could access it. and i added the connection property as described above by @yaprigal