locked
loading image files to application

    Question

  • I'm developing a windows store app. using javascript.

    I want to let users to pick some images from their hard drive and assign them to <img> tags in the application.

    I used FileOpenPicker to let user pick the file and then URL.createObjectURL(file) to create relative url for the files and assigned it to src property of my <img> tag and it works perfectly.

    the problem is that I want the application to load previously selected images next time user starts the app.

    I used msIndexedDB to store image's paths, so I have the absolute paths to those images (we assume that the file already exists)

    the question is how I can create Storagefile from those paths to use with URL.createObjectURL()?

    OR

    Do you have a better solution to this issue?




    • Edited by Ali.Ry Tuesday, November 13, 2012 7:24 AM
    Tuesday, November 13, 2012 7:20 AM

Answers

  • well i dont think the problem is the StorageFile, because that the same  as you get from the FilePicker.

    The problem is the access to the file; with the filepicker the user grants your application access to the file but after the application is restarted this access is no longer valid. The user have to select the files again, or you have to save / cache the access as well. find more information in this namespace: http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.accesscache.aspx


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by Ali.Ry Tuesday, November 13, 2012 6:43 PM
    Tuesday, November 13, 2012 3:37 PM
  • To confirm your answer, Dave, this is exactly what Windows.Storage.AccessCache is for, specifically the FutureAccessList object therein. You always have to use this mechanism to preserve permissions across app sessions if the app doesn't otherwise have programmatic access by default (its package or appdata folders) or by manifest capabilities (media libraries).

    In short, if you get a StorageFolder/File from the file picker and you want to preserve programmatic access for later sessions, you must use the AccessCahe.

    .Kraig

    • Marked as answer by Ali.Ry Tuesday, November 13, 2012 6:37 PM
    • Unmarked as answer by Ali.Ry Tuesday, November 13, 2012 6:37 PM
    • Marked as answer by Ali.Ry Tuesday, November 13, 2012 6:43 PM
    Tuesday, November 13, 2012 6:18 PM

All replies

  • well not sure about the createObjectURL but think it should work the same way as when with the filepicker.

    I think you got another issue. When you saved the image locations you dont save the access to the files. In WinRT the end user have togive you permission to the files, he can do that with a FilePicker but after the application is restarted this access is no longer available, or you have to "cache" that access like you do with the paths.

    look at this namespace: http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.accesscache.aspx it tells how to cache the acess to files.


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Tuesday, November 13, 2012 3:24 PM
  • well i dont think the problem is the StorageFile, because that the same  as you get from the FilePicker.

    The problem is the access to the file; with the filepicker the user grants your application access to the file but after the application is restarted this access is no longer valid. The user have to select the files again, or you have to save / cache the access as well. find more information in this namespace: http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.accesscache.aspx


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by Ali.Ry Tuesday, November 13, 2012 6:43 PM
    Tuesday, November 13, 2012 3:37 PM
  • To confirm your answer, Dave, this is exactly what Windows.Storage.AccessCache is for, specifically the FutureAccessList object therein. You always have to use this mechanism to preserve permissions across app sessions if the app doesn't otherwise have programmatic access by default (its package or appdata folders) or by manifest capabilities (media libraries).

    In short, if you get a StorageFolder/File from the file picker and you want to preserve programmatic access for later sessions, you must use the AccessCahe.

    .Kraig

    • Marked as answer by Ali.Ry Tuesday, November 13, 2012 6:37 PM
    • Unmarked as answer by Ali.Ry Tuesday, November 13, 2012 6:37 PM
    • Marked as answer by Ali.Ry Tuesday, November 13, 2012 6:43 PM
    Tuesday, November 13, 2012 6:18 PM