![](/img/trans.png)
[英]How to create an Azure Search Indexer using .net SDK (c#) to pull data from Azure blob storage
[英]How to write binary data as image into azure blob storage c#
首先,我是 azure 開發的新手,所以我的問題會模棱兩可。 我需要更好的建議。 我有 web api C# 接收二進制數據(圖像)。 我想將它寫入 azure blob 存儲。 就我而言,我需要檢查是否存在 blob 存儲然后寫入圖像,否則創建目錄並寫入圖像。
此目錄是公共讀取訪問權限,因此我可以在任何公共應用程序中反映圖像。
以下方法存儲圖像並返回圖像公共路徑
public class BlobStorageService : IBlobStorageService
{
public async Task<string> SaveSingleImage(byte[] image)
{
throw new NotImplementedException();
}
}
我已經做了。 以下是我的代碼。 這將獲取圖像字節並保存到 blob 存儲中並返回該圖像的公共 URL
public async Task<string> GoAppSaveSingleImage(ProofImageViewModel proofImage)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(GlobalConfig.Instance.AzureBlobStorageForGoAppImages);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(GlobalConfig.Instance.AzureBlobGoAppImagesContainerName);
CloudBlockBlob blockBlob = container.GetBlockBlobReference($"{proofImage.CountryCode}/{DateTime.Now.Year}/{DateTime.Now.Month}/{proofImage.ProofImage}");
blockBlob.Properties.ContentType = "image/png";
if (GlobalConfig.Instance.AzureBlobGoAppImagesIsStorageTier)
{
blockBlob.SetStandardBlobTierAsync((StandardBlobTier)GlobalConfig.Instance.AzureBlobGoAppImagesStorageTier).GetAwaiter().GetResult();
}
using (var stream = new MemoryStream(proofImage.ProofImage, writable: false))
{
await blockBlob.UploadFromStreamAsync(stream);
}
string publicUrl = blockBlob.Uri.AbsoluteUri;
return publicUrl;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.