【问题标题】:How can upload files to Azure Blob Storage from web site images?如何将文件从网站图像上传到 Azure Blob 存储?
【发布时间】:2017-09-21 10:23:21
【问题描述】:

如何将文件从 www.site.com/amazing.jpg 上传到 Azure Blob 存储? 多个从 url 上传文件到 Azure Blob 存储。 我找不到这条路。我尝试了很多方法都不成功:( 谢谢你的帮助

【问题讨论】:

  • 对 GauravMantri 的回答有任何顾虑吗?

标签: azure blob azure-storage azure-blob-storage blobstorage


【解决方案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");

【讨论】:

  • 非常感谢
猜你喜欢
  • 2013-07-29
  • 2020-01-25
  • 1970-01-01
  • 2021-01-16
  • 2019-10-30
  • 2018-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多