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


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

1

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