gpt4 book ai didi

c# - 如何在azure上上传图像列表并检索已上传图像的地址

转载 作者:行者123 更新时间:2023-12-03 03:12:03 25 4
gpt4 key购买 nike

我正在做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;
}

它需要对 azure 服务器进行四次调用,所以我想在一次调用中完成它,即在 azure 上上传四个图像的列表并检索上传图像的地址。

最佳答案

您需要进行单独的服务调用来上传单独的 blob。但是,您应该共享该方法中的大部分通用代码。也就是说,上面的所有内容实际上都获得了 blob 引用。只需在容器上调用一次 CreateIfNotExists,即可节省多次服务调用。

关于c# - 如何在azure上上传图像列表并检索已上传图像的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36012797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com