简体   繁体   English

将Blob上传到Windows Azure时指定特定地址

[英]Specify specific address when uploading blobs to windows azure

I am using .Net. 我正在使用.Net。 Is it possible to specify specific address for blobs when you upload blobs to window azure storage? 当您将Blob上传到Window Azure存储器时,是否可以为Blob指定特定的地址?

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. 我直接从windowsazure.com上的指南中得到了这个答案。 It was the #1 result for the phrase "upload file to azure blob storage" in google. 这是谷歌短语“将文件上传到azure blob存储”的第一结果。

I believe that in the GetBlockBlobReference method you can substitute "myblob" with the whatever you want the blob file name to be. 我相信,在GetBlockBlobReference方法中,您可以用所需的blob文件名替换“ myblob”。

// 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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