如何从www.site.com/amazing.jpg将文件上传到Azure Blob存储? 从网址多个上传文件到Azure Blob存储。 我找不到这种方式。我试过很多不成功的方法:( 谢谢你的帮助
答案 0 :(得分:1)
实际上非常简单,您可以要求Azure Storage为您完成工作:)。
基本上你要做的就是调用Copy Blob
操作。通过此操作,您可以指定任何可公开访问的URL,Azure存储服务将通过复制该URL的内容在Azure存储中为您创建Blob。
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");