none
DownloadToFileAsync(StorageFile file) is always empty

    Question

  • I am trying to write a wrapper class from uploading/downloading blobs from Azure Storage. Uploading is fine, and I only have one issue when downloading. I want to return a StorageFile and I have this:

          public async Task<bool> DownloadBlobStorageFileAsync(string connectionString, string containerName, string fileName)  
          {      
           var blockBlob = CloudStorageAccount.Parse(connectionString)
            .CreateCloudBlobClient()
            .GetContainerReference(containerName)
            .GetBlockBlobReference(fileName);
     
           StorageFile storageFile = null; //????????????
     
           blockBlob.DownloadToFileAsync(storageFile);
     
           return storageFile;
          }

    My storage file is always empty (length = 0), so my question is, how can I fill the storage file and return it?

    Friday, August 19, 2016 9:25 AM

Answers

  • The issue I see is you assigned Null to StorageFile. You will need to assign location that you want to download the Blob to storagefile. Below is an example (I haven't compiled or tested the code so you will need to modify/test to fit your needs)

                StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;

               StorageFile outputFile = await tempFolder.CreateFileAsync("output.file", CreationCollisionOption.GenerateUniqueName);

    Sunday, August 21, 2016 9:49 PM

All replies

  • Hello,

    We are checking on the query and would get back to you soon on this.

    I apologize for the inconvenience and appreciate your time and patience in this matter.

     

    Regards,

    Pradeep

    Saturday, August 20, 2016 10:41 AM
    Moderator
  • The issue I see is you assigned Null to StorageFile. You will need to assign location that you want to download the Blob to storagefile. Below is an example (I haven't compiled or tested the code so you will need to modify/test to fit your needs)

                StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;

               StorageFile outputFile = await tempFolder.CreateFileAsync("output.file", CreationCollisionOption.GenerateUniqueName);

    Sunday, August 21, 2016 9:49 PM
  • Thanks, that's how I've resolved it. Is there no way of returning a StorageFile type?
    Monday, August 22, 2016 5:31 PM