I need to upload a file from a form on the front-end, passing through the backend into the azure blob storage.
- I need save on the blob, and get the url saved on azure blob storage.
- I am receiving the file from the form on controller using a class to parse the data.
- The controller deals with the file and connect on the azure blob storage.
- The blob storage doesn't have example on his methods on documentation.
- All examples that I found just show how to upload from a local folder.
Following the code, the problem so far is the format of the myFile var is being passed on the method UploadFromStreamAsync.
// the controller starts here
[HttpPost]
public async System.Threading.Tasks.Task<ActionResult> Index(IFormFile arquivo)
{ //here I am receving the file
var myFile = arquivo.FileItem;
var myFileName = arquivo.FileName;
// here is the connection with blob account
string storageConnection = ConfigurationManager.AppSettings["BlobStorageString"];
string accountBlob = ConfigurationManager.AppSettings["BlobStorageAccount"];
var storageAccount = CloudStorageAccount.Parse(storageConnection);
var cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("hurrblobstest");
await cloudBlobContainer.CreateAsync();
var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference("filname12");
// here I am trying to send the file
await cloudBlockBlob.UploadFromStreamAsync(myFile);
var result = JsonConvert.SerializeObject(cloudBlockBlob);
//here I need to return the url or the object with the file info on the azure blob storage
return Json(result);
}
I am getting a message on the: await cloudBlockBlob.UploadFromStreamAsync(myFile); that tells me that the file
HttpPostedFileBase cannot be converted into System.IO.Stream