Copy file from url in Azure blob

I have a file with a remote url, for example http://www.site.com/docs/doc1.xls , and I would like to copy this file to my BLOB account.

I know and know about uploading files to the BLOB repository, but I was not sure how this can be done for a file with a remote URL.

+3
source share
1 answer

Try to find CloudBlockBlob.StartCopyFromBlob that accepts URIs if you use 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 published this when he first came out. Handy and his message show how to watch for completion since the Async operation.

+7
source

Source: https://habr.com/ru/post/1207165/


All Articles