Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
private async Task<string> UploadBlobStorage(IFormFile filepayupload)
string url = string.Empty;
if (filepayupload != null)
using (var stream = new MemoryStream())
await filepayupload.CopyToAsync(stream);
var streamArray = stream.ToArray();
MemoryStream streamFinal = new MemoryStream(streamArray)
Position = 0
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionStorage);
var client = storageAccount.CreateCloudBlobClient();
var container = client.GetContainerReference(containerReferrence);
var fileName = Guid.NewGuid() + filepayupload.FileName;
CloudBlockBlob blockBlobImage = container.GetBlockBlobReference(fileName);
blockBlobImage.Properties.ContentType = filepayupload.ContentType;
blockBlobImage.Metadata.Add("DateCreated", DateTime.UtcNow.ToLongDateString());
blockBlobImage.Metadata.Add("TimeCreated", DateTime.UtcNow.ToLongTimeString());
await blockBlobImage.UploadFromStreamAsync(streamFinal);
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
url = blob.Uri.ToString();
// Now the file is loaded into the stream variable
return url;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.