【发布时间】:2015-10-19 19:30:45
【问题描述】:
我正在使用 Azure 存储来存储和检索图像。我有这个方法来保存图像(blob):
public void SaveBlob(string containerName, string blobName, byte[] blob)
{
// Retrieve reference to the blob
CloudBlockBlob blockBlob = GetContainer(containerName, true).GetBlockBlobReference(blobName);
using (var stream = new MemoryStream(blob, writable: false))
{
blockBlob.UploadFromStream(stream);
}
}
这是 GetContainer 方法:
public CloudBlobContainer GetContainer(string containerName, bool createIfNotExist)
{
if (string.IsNullOrEmpty(containerName))
return null;
// Retrieve a reference to a container. If container doesn't exist, optionally create it.
CloudBlobContainer container = this._blobClient.GetContainerReference(containerName);
if (container == null && !createIfNotExist)
return null;
// Create the container if it doesn't already exist. It will be private by default.
container.CreateIfNotExists(BlobContainerPublicAccessType.Off, null, null);
return container;
}
这里发生的情况是,当我尝试保存 blob 时,我首先获得了对容器的引用。如果容器不存在,则创建它,然后保存 blob。如果我必须先创建容器然后立即将 blob 保存到其中,我会在这里遇到时间问题吗?我担心的是,我可能会在 Azure 完成创建之前尝试将 blob 保存到容器中。或者这不是问题?
【问题讨论】:
标签: azure azure-storage