How can upload files to Azure Blob Storage from web site images?

老子叫甜甜 提交于 2019-12-13 22:39:28

问题


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


来源:https://stackoverflow.com/questions/43593136/how-can-upload-files-to-azure-blob-storage-from-web-site-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!