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

Output to thumbnails container not working. #22

Open BradAtConfluent opened 3 years ago

BradAtConfluent commented 3 years ago

Following the tutorial here: https://docs.microsoft.com/en-us/azure/event-grid/resize-images-on-storage-blob-upload-event?tabs=dotnet

Installation went well and when upload an image to the image container the Thumbnail function seems to run successfully. However there are not images showing up in the thumbnail container.

Current Code: local.settings.json { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=egthumbnail;AccountKey=xxxxxxxxx;", "FUNCTIONS_WORKER_RUNTIME": "dotnet", "THUMBNAIL_CONTAINER_NAME": "thumbnails", "THUMBNAIL_WIDTH": "100", "datatype": "binary" } }

function.json { "generatedBy": "Microsoft.NET.Sdk.Functions-3.0.2", "configurationSource": "attributes", "bindings": [ { "type": "eventGridTrigger", "name": "eventGridEvent" } ], "disabled": false, "scriptFile": "../bin/ImageFunctions.dll", "entryPoint": "ImageFunctions.Thumbnail.Run" }

mustay commented 3 years ago

Facing the same issue. Were you able to resolve it?

lindacmsheard commented 2 years ago

For anybody else coming across this: I was able to solve it by following the advice here: https://stackoverflow.com/a/53314953: There are a couple of edits required to connect to the storage account that the eventtrigger is configured to run on:

Ensure you have an app setting (custom name, here MY_STORAGE_ACCOUNT) with the connection string to the storage account where your images land, for example with the azure cli:

az functionapp config appsettings set --name $functionAppName --resource-group $ResourceGroup --settings  MY_STORAGE_ACCOUNT=<your connection string> THUMBNAIL_CONTAINER_NAME=thumbnails THUMBNAIL_WIDTH=100

line 35 becomes

//      private static readonly string BLOB_STORAGE_CONNECTION_STRING = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
        private static readonly string BLOB_STORAGE_CONNECTION_STRING = Environment.GetEnvironmentVariable("MY_STORAGE_ACCOUNT");

line 79 becomes

//      [Blob("{data.url}", FileAccess.Read)] Stream input,
        [Blob("{data.url}", FileAccess.Read, Connection = "MY_STORAGE_ACCOUNT")] Stream input,