DownloadToFileAsync filename? RRS feed

  • Question

  • CloudBlobContainer blobContainer = BlobService.GetBlobContainer(deviceModel.BlobSasUri);
         StorageFolder localFolder = ApplicationData.Current.LocalCacheFolder;
         StorageFile screenshot = await localFolder.CreateFileAsync(deviceModel.StudentId + "_thumb.jpeg", CreationCollisionOption.ReplaceExisting);
         CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(deviceModel.StudentId + ".jpeg");
         await blockBlob.DownloadToFileAsync(screenshot);

    In the above code, I specify to create a file with a specific file name: student id + "_thumb.jpeg" However, DownloadToFileAsync  creates it's own file name, but what's funny is that it adds the "_thumb.jpeg" text to its own filename.

    For example, if the student id is "alexo@microsoft.com", DownloadToFileAsync will create a file called "alexoh_thumb.jpeg".

    CreateFileAsync does end up creating an empty file with the correct file name. Something tells me I don't need to call CreateFileAsync, but then I don't know how to provide DownloadToFileAysnc with a StorageFile.

    Also, there seems to be no documentation for DownloadToFileAsync. CloudBlob does not contain the method DownloadToFileAsync(StorageFile ...), and CloudBlockBlob has this method, but none with a parameter of FileStorage.

    Friday, June 9, 2017 8:56 PM

All replies

  • Hm, I just tested a string that doesn't contain "@" and "." (probably thinks .com is a file extension?) characters. Creates the file with the correct name now, however, it also creates an empty 0-byte file with an incorrect name. For example:

    Correct file name: "uswafwsd_Proh_thumb.jpeg" was created

    Empty file created with name: "uswafwsd_Oh_thumb.jpeg"

    Why is the empty file being made and how is it's name determined? Where is the "Oh" text coming from?

    • Edited by Qoheleth07 Friday, June 9, 2017 9:09 PM
    Friday, June 9, 2017 9:07 PM
  • The DownloadToFileAsync API writes to the file specified. You should try writing to this file directly and observe whether you see the same issue. There is no reinterpretation/change in the filename at the storage layer.

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    • Edited by Md Shihab Wednesday, June 14, 2017 2:27 AM
    • Proposed as answer by Md Shihab Wednesday, June 14, 2017 2:27 AM
    Wednesday, June 14, 2017 2:25 AM