我使用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保存到容器中。或许这不是一个问题?
答案 0 :(得分:2)
查看您的代码,我认为您不会遇到任何计时问题,因为- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[_popover dismissPopoverAnimated:YES];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (_popover) {
[_popover presentPopoverFromRect:frameRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
}
方法是一种同步方法,并且只会在创建容器时返回。此外,对于Azure Blob存储(与Amazon S3不同),该方法将立即创建容器,或者如果不能这样做(或者换句话说Azure存储为CreateIfNotExists
)则抛出错误。
此外,我认为这段代码是多余的:
Strongly Consistent
由于if (container == null && !createIfNotExist)
return null;
永远不会等于container
,因此null
条件永远不会是if
。