【发布时间】:2018-12-16 09:43:47
【问题描述】:
我需要能够在 REACT UI 中选择一个文件,然后它将以发布的文件作为参数之一调用 REST 服务,然后上传到 Azure 存储
我有这样的事情:
public async Task<IHttpActionResult> PutTenant(string id, Tenant tenant, HttpPostedFile certificateFile)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureStorageKey"].ToString());
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(ConfigurationManager.AppSettings["certificatesContainer"].ToString());
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(certificateFile))
{
blockBlob.UploadFromStream(fileStream);
}
var tenantStore = CosmosStoreFactory.CreateForEntity<Tenant>();
tenant.CertificatePath = blockBlob.Uri;
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != tenant.TenantId)
{
return BadRequest();
}
var added = await tenantStore.AddAsync(tenant);
return StatusCode(HttpStatusCode.NoContent);
}
openread 行是我不确定的地方,如何获取 HttpPostedFile 然后上传到 Azure 存储。
【问题讨论】:
标签: c# .net asp.net-web-api asp.net-web-api2 azure-storage