我有將圖像上傳到 azure blob 存儲(chǔ)的代碼這是上傳圖像的代碼public async Task<string> UploadFile(IFormFile file) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_configuration.GetConnectionString("AccessKey")); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("toosee"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(file.FileName); using (var fileStream = file.OpenReadStream()) { await blockBlob.UploadFromStreamAsync(fileStream); } return blockBlob.Uri.ToString(); }結(jié)果我得到了網(wǎng)址當(dāng)我打開(kāi)它時(shí),圖像下載。我只需要看一下,我的問(wèn)題出在哪里?
1 回答

阿波羅的戰(zhàn)車(chē)
TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
如果它沒(méi)有反映所需/預(yù)期的行為,請(qǐng)忽略此答案。
- - 觀察到的 - -
如果Web 瀏覽器正在下載圖像 blob,如下所示:
- - 預(yù)期的 - -
并且,所需的行為是 Web 瀏覽器將其呈現(xiàn)如下:
- - 使固定 - -
然后,將以下行添加到您的代碼中:
blockBlob.Properties.ContentType = "圖片/png";
下面找到一個(gè)示例代碼:
??public?static?string?UploadFile() ????{ ????????CloudStorageAccount?storageAccount?=?CloudStorageAccount.Parse("{Connection?String}"); ????????CloudBlobClient?blobClient?=?storageAccount.CreateCloudBlobClient(); ????????CloudBlobContainer?container?=?blobClient.GetContainerReference("toosee"); ????????CloudBlockBlob?blockBlob?=?container.GetBlockBlobReference("customer_address.png"); ????????blockBlob.Properties.ContentType?=?"image/png"; ????????blockBlob.UploadFromFile(@"C:\\Temp\\customer_address.PNG"); ????????????????return?blockBlob.Uri.ToString(); ????}
- 1 回答
- 0 關(guān)注
- 115 瀏覽
添加回答
舉報(bào)
0/150
提交
取消