Search code examples
azurewindows-runtimeazure-storagewin-universal-appstoragefile

Uploading a StorageItemThumbnail to Azure blob storage from a Windows Universal app


I am building a Windows Universal app.

I have a Windows.Storage.FileProperties.StorageItemThumbnail obtained from a Windows.Storage.StorageFile as the result of a call to StorageFile.GetThumbnailAsync.

Now I need to upload the thumbnail to Azure blob storage.

The correct method appears to be UploadFromFileAsync or UploadFromStreamAsync on Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.

But the only documentation I can find for UploadFromFileAsync is misleading in my case. All the method overloads documented there include a System.IO.FileMode parameter, which is not available under Windows Runtime / Windows Universal. These are the two overloads actually available to me:

    public IAsyncAction UploadFromFileAsync(StorageFile source);
    public IAsyncAction UploadFromFileAsync(StorageFile source, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext);

though I do not know where to find them documented.

How do I upload the StorageItemThumbnail to Azure blob storage using the CloudBlockBlob?


Solution

  • It turns out to be very straightforward:

        public async void UploadThumbnailToBlob(Windows.Storage.FileProperties.StorageItemThumbnail thumbnail, Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blob)
        {
            await blob.UploadFromStreamAsync(thumbnail);
        }