I am trying to upload a file to Azure blob storage in Asp .Net Core. Everything seems to be working but no file is uploaded. Here is my code snippet:
var blobReference = GetBlobReference();
rawData.Position = 0;
// var result = blobReference.UploadFromStreamAsync(rawData);
var result = blobReference.UploadFromFileAsync("C:\\users\\tjaartb\\Downloads\\DebitOrderMandate.pdf");
result.GetAwaiter().GetResult();
var blobPath = blobReference.Uri.ToString();
What's happening?
The debugger steps over the result.GetAwaiter().GetResult() with no exceptions occurring. Checking the result Task variable after the GetResult() call shows that the task state is RanToCompletion and the exception property is blank. My blob container is created successfully in earlier code indicating that the connection to blob storage is successful. GetResult() finishes instantly, so it seems like nothing is happening.
Things I've checked
rawDatais aMemoryStreamthat is populated with file data. Using the commented line to try and upload via a stream is not successful either.- The connection to Azure is working.
- The file path exists.
- There are no exceptions thrown.
- The only thing in my debug window output is
Started Thread <ThreadNumber> - Putting an invalid path in the call to
blobReference.UploadFromFileAsync()throws aFileNotFoundExceptionas expected. - I've tried downgrading my project to
netcoreapp2.0fromnetcoreapp2.1with no success.