I'm trying to have an Azure function create a file on the blob storage with a given filename. I'm not getting any errors, but also the file doesn't seem to appear. It doesn't work locally, or when deployed.
I'm not very experienced with setting up the blob storage and its access, what am I missing?
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace My.Functions
{
public static class UploadGhost
{
[FunctionName("UploadGhost")]
[StorageAccount("AzureWebJobsStorage")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log,
IBinder binder)
{
string filename = "ghostsdev/myFile.txt";
var attribute = new BlobAttribute(filename, FileAccess.Write);
attribute.Connection = "AzureWebJobsStorage";
using (var writer = await binder.BindAsync<TextWriter>(attribute))
{
writer.Write("myData");
log.LogInformation("I made a file! or did I... ");
}
return new OkObjectResult("Executed without errors!");
}
}
}
output:
2021-09-17T17:13:07 Welcome, you are now connected to log-streaming service. The default timeout is 2 hours. Change the timeout with the App Setting SCM_LOGSTREAM_TIMEOUT (in seconds).
2021-09-17T17:13:15.436 [Information] Executing 'UploadGhost' (Reason='This function was programmatically called via the host APIs.', Id=3d956f6a-e9c5-42fc-bf8d-d1ff55810f9c)
2021-09-17T17:13:15.849 [Information] I made a file! or did I...
2021-09-17T17:13:16.030 [Information] Executed 'UploadGhost' (Succeeded, Id=3d956f6a-e9c5-42fc-bf8d-d1ff55810f9c, Duration=615ms)
EDIT: I was unaware there was a storage account associated with the functions by default, and the files were appearing there.

