How can upload file to Azure Blob Storage from www.site.com/amazing.jpg ? Multiple upload files to Azure Blob Storage from urls. I cant find this way. I tried many way unsuccesful :( thank you for help
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It's actually pretty simple and you can ask Azure Storage to do the work for you :).
Essentially what you have to do is invoke Copy Blob
operation. With this operation, you can specify any publicly accessible URL and Azure Storage Service will create a blob for you in Azure Storage by copying the contents of that URL.
var cred = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("temp");
var blob = container.GetBlockBlobReference("amazing.jpg");
blob.StartCopy(new Uri("www.site.com/amazing.jpg"));
//Since copy is async operation, if you want to see if the blob is copied successfully, you must check the status of copy operation
do
{
System.Threading.Thread.Sleep(1000);
blob.FetchAttributes();
var copyStatus = blob.CopyState.Status;
if (copyStatus != CopyStatus.Pending)
{
break;
}
} while (true);
Console.WriteLine("Copy operation finished");