C#Azure存储-如何将文件上传到已经存在的容器 [英] C# Azure Storage - How to Upload a File to an already Existing Container

查看:123
本文介绍了C#Azure存储-如何将文件上传到已经存在的容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望获得有关如何将文件上传到Azure存储中现有容器的帮助.我遵循了 Azure文档-但它似乎指向创建一个新容器并在那里上传文件.如果我已经预先在Azure中创建了一个容器,例如"testresult1",然后尝试使用C#代码将文件上传到那里,那么它会抱怨容器"testresult1"已经存在.

Hoping for a bit of help on how to upload a file into an existing container in Azure Storage. I have followed Azure doc - but it seem to pointing to creating a new container and upload a file there. If I already create a container beforehand in Azure, for example, as "testresult1", and then try to upload a file there using C# code then it complains that the container "testresult1" already exists.

这是我使用的错误代码:

Here is the code I've used that is wrong:

CloudBlobContainer = cloudBlobClient.GetContainerReference("testresult1");

Microsoft doc中的示例代码可以正常工作,但是它创建了一个新容器"quickstartblobs"和GUID,然后将文件上传到该容器.我试图查看是否有一个选项,如果一个容器已经存在,那么我们如何使用代码将一个或多个文件上传到该容器中,而不必为每个上传的文件创建一个新的容器.

The sample code in Microsoft doc works without having any issue, but it creates a new container, "quickstartblobs" plus the GUID, then uploads the file there. I am trying to see if there is any option where if a container already exists then how we can upload one or more files into that container using the code, without creating a new container for each uploaded file.

一个相关的问题:在Azure存储中可以创建多少个容器有上限吗?与Azure订阅有关吗?

A relevant question: is there any upper limit on how many containers can be created in Azure Storage? Is it related to Azure subscription?

谢谢.

推荐答案

您可以使用

You could use CreateIfNotExistsAsync method, which initiates an asynchronous operation that creates the container if it does not already exist.

使用以下代码获取您现有的容器,并按照Doc继续上传文件.

Use the following code to get your existed container and follow the Doc to go on uploading file.

cloudBlobContainer = cloudBlobClient.GetContainerReference("testresult1");
await cloudBlobContainer.CreateIfNotExistsAsync();

在Azure存储中可以创建多少个容器是否有上限?与Azure订阅有关吗?

is there any upper limit on how many containers can be created in Azure Storage? Is it related to Azure subscription?

每个存储帐户的最大Blob容器数,Blob,文件共享,表,队列,实体或消息没有限制.

Max number of blob containers, blobs, file shares, tables, queues, entities, or messages per storage account is no limit.

单个blob容器的最大大小为500 TiB.每个Blob容器最多可存储5个访问策略.

And max size of single blob container is 500 TiB. Max number of stored access policies per blob container is 5.

有关更多详细信息,您可以参考 azure订阅服务限制.

For more details, you could refer to azure subscription service limits.

这篇关于C#Azure存储-如何将文件上传到已经存在的容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆