Reputation: 109
I've created a blob trigger that accepts a file from a blob, unzips it and moves it to another blob using streams.
My code looks like this
[FunctionName("Requests")]
[StorageAccount("samplecontainer")]
public static void Run([BlobTrigger("incoming/{name}")]Stream myBlob,
[Blob("processing/{name}.xml", FileAccess.Write)] TextWriter output,
string name, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
string returnValue;
using (Stream blob = myBlob)
{
using (GZipStream decompressionStream = new GZipStream(blob, CompressionMode.Decompress))
{
log.LogInformation($"Unzipping file");
name = name.Replace(".gz", "");
var content = String.Empty;
using (StreamReader reader = new StreamReader(decompressionStream))
{
content = reader.ReadToEnd();
reader.Close();
}
returnValue = content;
}
}
log.LogInformation($"C# Blob trigger function finished processing blob\n Name:{name} \n Now writing to xml");
output.WriteLine(returnValue);
}
This will in fact work while running this locally using "AzureWebJobsStorage": "UseDevelopmentStorage=true" in my local.settings.json file.
However, once I've deployed this app and upload a file to the real container using Azure Storage Explorer nothing happens and the activity log shows that the operation failed in Write.Tiny.txt.gz, Could not find file 'D:\home\site\wwwroot\Requests\tiny.txt.gz'.
I have http triggers that do work, and I have tried turning off the configuration WEBSITE_RUN_FROM_PACKAGE to no effect. Am I maybe missing some setting or config? When I console into this path in the function app and cat the function.json I get this:
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.29",
"configurationSource": "attributes",
"bindings": [
{
"type": "blobTrigger",
"connection": "samplecontainer",
"path": "incoming/{name}",
"name": "myBlob"
}
],
"disabled": false,
"scriptFile": "../bin/azure-functions.dll",
"entryPoint": "Requests.Run"
}
Upvotes: 0
Views: 1102
Reputation: 109
I fully believe I also needed Bowman Zhu's answer for this to work, but in my specific case I had forgotten to add the storage account as a connection string in my appSettings.json, as we had recently updated to Microsoft.Azure.WebJobs.Extensions.Storage version 3 and this was our first blob trigger.
In appSettings.json:
{
"ConnectionStrings": {
"AzureWebJobsStorage": "{endpoint}"
}
}
Upvotes: 1
Reputation: 14088
OK, I can reproduce your problem.
Since you can work on local, then it should be no problem about your code.
I can explain why this happened. Your function app on azure don't have the RBAC that can write data to azure blob storage.
Below steps can solve the problem:
First, create identity of your function app.
Second, add RBAC role of your function app to storage account.
By the way, the above settings will not take effect immediately, you need to wait a few minutes for it to take effect.
Upvotes: 2