locked
Download images for offline use

    Question

  • Is there a way to download images to a local app storage and use them later if the system is offline as source for an img tag or as background image for a div element?

    As alternative I could although think about an iframe that loads from the local storage but so far I haven’t found any information if it is possible in a metro app to direct an iframe to the local disk storage at all. All the samples use only ms-wwa, ms-wwa-web, http or https.

    Saturday, September 17, 2011 10:13 AM

Answers

  • This BUILD session will give you the answer: http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-894T


    T.A., Founder and CEO, Apexa, www.apexa.co
    Sunday, September 18, 2011 9:02 AM
  • Checkout the code in the blob sample, http://code.msdn.microsoft.com/Blob-Sample-0e35889e/sourcecode?fileId=43594&pathId=1754477665

    For downloading a file and saving it to local storage, check out the implementation of function scenario4DownloadAndSave. In here you will find how to download a file and save it to disk. In the same the Application is using the WinRT File API to save it into the pictures library (see function writeBlobToFile). You can change the function writeBlobToFile to use Windows.Storage.ApplicationData.localFolder instead of using Windows.Storage.KnownFolders.picturesLibrary to write the file off to the App's local storage.

    For loading a file and showing it in the image tag, check out the implementation of scenario1OpenImage function in the same sample. In this case as well you would need to replace the picker code with the code to load the image from the local storage through Windows.Storage.ApplicationData.localFolder.

    Hope this helps, thanks

    Harris


    Harris
    Friday, September 23, 2011 8:03 PM

All replies

  • This BUILD session will give you the answer: http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-894T


    T.A., Founder and CEO, Apexa, www.apexa.co
    Sunday, September 18, 2011 9:02 AM
  • Checkout the code in the blob sample, http://code.msdn.microsoft.com/Blob-Sample-0e35889e/sourcecode?fileId=43594&pathId=1754477665

    For downloading a file and saving it to local storage, check out the implementation of function scenario4DownloadAndSave. In here you will find how to download a file and save it to disk. In the same the Application is using the WinRT File API to save it into the pictures library (see function writeBlobToFile). You can change the function writeBlobToFile to use Windows.Storage.ApplicationData.localFolder instead of using Windows.Storage.KnownFolders.picturesLibrary to write the file off to the App's local storage.

    For loading a file and showing it in the image tag, check out the implementation of scenario1OpenImage function in the same sample. In this case as well you would need to replace the picker code with the code to load the image from the local storage through Windows.Storage.ApplicationData.localFolder.

    Hope this helps, thanks

    Harris


    Harris
    Friday, September 23, 2011 8:03 PM