简体   繁体   中英

Specify specific address when uploading blobs to windows azure

I am using .Net. Is it possible to specify specific address for blobs when you upload blobs to window azure storage?

Because I want to have the link to the file before the file finishes uploading. I don't care if the link don't work, I just want to have the link first.

I heard that this is possible, but I couldn't find any reference to it. I was told to generate the file identifier and then upload the file with that identifier.

Thanks in advance!

I got this answer straight from guide on windowsazure.com. It was the #1 result for the phrase "upload file to azure blob storage" in google.

I believe that in the GetBlockBlobReference method you can substitute "myblob" with the whatever you want the blob file name to be.

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
    blockBlob.UploadFromStream(fileStream);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM