我需要从前端的窗体上传一个文件,通过后端进入Azure Blob存储。
在代码之后,到目前为止的问题是myFile var的格式正在传递给方法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);
}
我收到一条消息:等待cloudBlockBlob。UploadFromStreamAsync(myFile)代码>它告诉我文件
无法将HttpPostedFileBase转换为System.IO.流
嗯,我说如果有东西想要一个流,给它一个流:
using (Stream stream = myFile.OpenReadStream())
{
await cloudBlockBlob.UploadFromStreamAsync(stream);
}