我在做Mvc asp.net项目。我想在azure blob存储上传四个图像,我一次使用以下方法上传一个图像
public static string UploadToBlob(string fileName, byte[] data)
{
MemoryStream file = new MemoryStream(data);
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("ConnectionSetting"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
// Create the container if it doesn't already exist.
container.CreateIfNotExists();
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
blob.Properties.ContentType = "image/jpg";
blob.UploadFromStream(file);
string url = blob.Uri.ToString();
return url;
}
它需要四次调用天蓝色服务器,所以我想在一次调用中进行,即上传天蓝色的四个图像列表并检索上传图像的地址。
答案 0 :(得分:1)
您需要进行单独的服务调用才能上传单独的blob。但是,您应该共享该方法中的大多数常用代码。也就是说,以上所有内容实际上都获得了blob引用。这只会在容器上调用一次CreateIfNotExists,从而为您节省几个服务调用。