本文介绍了如何从网站映像将文件上传到Azure Blob存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

实际上非常简单,您可以要求Azure存储为您完成工作:).

It's actually pretty simple and you can ask Azure Storage to do the work for you :).

基本上,您需要做的是调用Copy Blob操作.通过此操作,您可以指定任何公共可访问的URL,并且Azure存储服务将通过复制该URL的内容在Azure存储中为您创建一个Blob.

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");

这篇关于如何从网站映像将文件上传到Azure Blob存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 02:13