I am writing a small web application for Windows Azure, which should use the blob storage for, obviously, storing blobs.

Is there a function or a way to automatically generate a unique name for a blob on insert?

有帮助吗?

解决方案

You can use a Guid for that:

string blobName = Guid.NewGuid().ToString();

其他提示

There is nothing that generates a unique name "on insert"; you need to come up with the name ahead of time.

When choosing the name of your blob, be careful when using any algorithm that generates a sequential number of some kind (either at the beginning or the end of the name of a blob). Azure Storage relies of the name for load balancing; using sequential values can create contention in accessing/writing to Azure Blobs because it can prevent Azure from properly load-balancing its storage. You get 60MB/Sec on each node (i.e. server). So to ensure proper load-balancing and to leverage 60MB/Sec on multiple storage nodes you need to use random names for your blobs. I typically use Guids to avoid this problem, just as Sandrino is recommending.

In addition to what Sandrino said (using GUID which have very low probability of being duplicated) you can consider some third-party libraries which generate conflict-free identifiers example: Flake ID Generator

EDIT

Herve has pointed out very valid Azure Blob feature which should be considered with any blob names, namely, Azure Storage load balancing and blobs partitioning.

Azure keeps all blobs in partition servers. Which partition server should be used to store particular blob is decided on the blob container and the blob file name. Unfortunately I was not able to find and documentation describing algorithm used for blobs partitioning.

More on Azure Blob architecture can be found on Windows Azure Storage Architecture Overview article.

This is an old post, but it was the first hit that showed up for 'azure storage blob unique id' search.

It looks like the 'metadata_storage_path' generated property is unique, but it's not filterable so it may not be useful for some purposes.

enter image description here

enter image description here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top