Copy file from URL to Azure BLOB

后端 未结 1 413
没有蜡笔的小新
没有蜡笔的小新 2020-12-16 06:00

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 uploa

相关标签:
1条回答
  • 2020-12-16 06:19

    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.

    0 讨论(0)
提交回复
热议问题