locked
How to save PNG data URL to disk?

    Question

  • I have a data URL with a PNG image. Is there a way to save this to disk?
    Tuesday, June 19, 2012 8:21 PM

Answers

All replies

  • Yes,

    You can create an image object set its URL and then use it's blob to write to a file.  There are several forum posts on saving image data.  You could also directly save the data from an xhr request (I don't know if there is an example of that but should be pretty easy)

    http://social.msdn.microsoft.com/Search/en-US/windows/apps?query=save%20image%20to%20disk&rq=meta:Search.MSForums.ForumID(0befe8a5-d7fb-40ee-882a-2a143bc73489)+site:microsoft.com&rn=Building+Metro+style+apps+with+HTML5%2fJavaScript+Forum

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, June 20, 2012 2:03 PM
    Moderator
  • Yes, got it working with the Blob sample from the SDK. Not sure if that is the most efficient way though. But fast enough :)
    I wonder though, what happens if my app is getting suspended while its in the process of writing to the disk. The file would then be not written (completely) would it?
    Wednesday, June 20, 2012 2:05 PM
  • Hi,

      >> what happens if my app is getting suspended while its in the process of writing to the disk. The file would then be not written (completely)

    When the app is being suspended, you will have several seconds to do whatever you want to save the state. During those several seconds, user cannot interact with UI (as the app is in background), so no new commands will be queued. Usually saving an image file takes less than 1 second. thus it will not be an issue. If you have concern on what if power is suddenly cut, you check if the image on the disk is valid when the next time the app starts. If it’s invalid, you download it from the source and save it to disk again.

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework

    Friday, June 22, 2012 10:48 AM
    Moderator