Search code examples
javascripthtmlwindows-runtimewindows-store-appswinjs

How can I create a StorageFile object from URI?


I'm working on a HTML+JS app. I have to launch image file from Internet in native photo app.

Code to launch:

var uri = new Windows.Foundation.Uri("http://someuri.com/somefile.JPG");
    Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(
      function (file) {
          // Launch the retrieved file using the default app
          Windows.System.Launcher.launchFileAsync(file).then(
            function (success) {
                if (success) {
                    // File launched
                } else {
                    // File launch failed
                }
            }
          );
      }
    );

There is problem with file variable should be a StorageFile class. I can't create this class from URI. Which method should I choose (look into link)?

Method getFileFromApplicationUriAsync only gets files from other application, not from web.
Method createStreamedFileFromUriAsync isn't available on WP 8.1.
Method getFileFromPathAsync doesn't support URIs.


Solution

  • I am afraid your only option is to download the file to local storage, and then go from there.