我正在將檔案位元組陣列保存到 azure blob,但我發現擴展名沒有保存。保存檔案后,將回傳檔案的全名和擴展名。我希望當我單擊鏈接時,檔案應該在瀏覽器中打開,但我得到了..
<Error>
<Code>ResourceNotFound</Code>
<Message>The specified resource does not exist. RequestId:6012e9b1-901e-011b-57e9-447dc0000000 Time:2022-03-31T10:21:29.3337046Z</Message>
</Error>
public async Task<string> UploadFileToBlobAsync(string strFileName, byte[] fileData, string fileMimeType)
{
var accessKey = _configuration.GetValue<string>("ConnectionStrings:AzureBlob");
CloudStorageAccount csa = CloudStorageAccount.Parse(accessKey);
CloudBlobClient cloudBlobClient = csa.CreateCloudBlobClient();
string containerName = "api-v2-files"; //Name of your Blob Container
CloudBlobContainer cbContainer = cloudBlobClient.GetContainerReference(containerName);
if (await cbContainer.CreateIfNotExistsAsync())
{
await cbContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
}
if (strFileName != null && fileData != null)
{
CloudBlockBlob cbb = cbContainer.GetBlockBlobReference(strFileName);
cbb.Properties.ContentType = fileMimeType;
await cbb.UploadFromByteArrayAsync(fileData, 0, fileData.Length);
return cbb.Uri.AbsoluteUri;
}
return "";
}
uj5u.com熱心網友回復:
問題在于以下代碼行:
if (await cbContainer.CreateIfNotExistsAsync())
{
await cbContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
}
if如果容器已經存在于您的存盤帳戶中,則基本上您的代碼不會被阻塞。因此,您的容器的訪問級別不會更改。
假設您使用的是 SDK 版本 11,請使用以下覆寫CreateIfNotExists: CreateIfNotExistsAsync(BlobRequestOptions, OperationContext, CancellationToken)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/453990.html
標籤:C# 网 asp.net 核心 天蓝色 blob 存储
