Copy file from URL to Azure BLOB

淺唱寂寞╮ 提交于 2019-11-27 18:56:29

问题


I have a file at a remote url such as http://www.site.com/docs/doc1.xls and i would like to copy that file onto my BLOB storage account.

I am aware and know of uploading files to a BLOB storage but wasn't sure how this can be done for a file from remote URL.


回答1:


Try looking at CloudBlockBlob.StartCopyFromBlob that takes a URI if you are using the .NET client library.

string accountName = "accountname";
string accountKey = "key";
string newFileName = "newfile2.png";
string destinationContainer = "destinationcontainer";
string sourceUrl = "http://www.site.com/docs/doc1.xls";

CloudStorageAccount csa = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
CloudBlobClient blobClient = csa.CreateCloudBlobClient();
var blobContainer = blobClient.GetContainerReference(destinationContainer);
blobContainer.CreateIfNotExists();
var newBlockBlob = blobContainer.GetBlockBlobReference(newFileName);
newBlockBlob.StartCopyFromBlob(new Uri(sourceUrl), null, null, null);

Gaurav posted about this when it first came out. Handy, and his post shows how to watch for completion since the operation is Async.



来源:https://stackoverflow.com/questions/20413627/copy-file-from-url-to-azure-blob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!