【问题标题】:Copy file from URL to Azure BLOB将文件从 URL 复制到 Azure BLOB
【发布时间】:2013-12-23 04:45:06
【问题描述】:

我在远程 URL 上有一个文件,例如 http://www.site.com/docs/doc1.xls,我想将该文件复制到我的 BLOB 存储帐户中。

我知道并知道将文件上传到 BLOB 存储,但不确定如何为来自远程 URL 的文件执行此操作。

【问题讨论】:

    标签: azure azure-blob-storage


    【解决方案1】:

    如果您使用的是 .NET 客户端库,请尝试查看带有 URI 的 CloudBlockBlob.StartCopyFromBlob。

    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 首次发布时就发布了此消息。很方便,his post 展示了如何观察完成,因为操作是异步的。

    【讨论】:

    • 谢谢,迈克。快速说明:Blob 的 StartCopyFromBlob 方法现已弃用,取而代之的是 StartCopy。
    猜你喜欢
    • 2019-03-19
    • 1970-01-01
    • 2020-08-18
    • 2021-07-29
    • 1970-01-01
    • 2017-08-03
    • 2019-04-01
    • 2017-05-06
    • 2019-08-12
    相关资源
    最近更新 更多