我有將圖像上傳到 azure blob 存儲的代碼這是上傳圖像的代碼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(); }結果我得到了網址當我打開它時,圖像下載。我只需要看一下,我的問題出在哪里?
1 回答
阿波羅的戰車
TA貢獻1862條經驗 獲得超6個贊
如果它沒有反映所需/預期的行為,請忽略此答案。
- - 觀察到的 - -
如果Web 瀏覽器正在下載圖像 blob,如下所示:

- - 預期的 - -
并且,所需的行為是 Web 瀏覽器將其呈現如下:

- - 使固定 - -
然后,將以下行添加到您的代碼中:
blockBlob.Properties.ContentType = "圖片/png";
下面找到一個示例代碼:
??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 關注
- 117 瀏覽
添加回答
舉報
0/150
提交
取消
