Search code examples
javascripttizentizen-web-apptizen-wearable-sdk

How do I use a downloaded svg file within my application using Tizen Web studio?


I can get an SVG file downloaded, additionally, I can display svg files as you would normally within an image tag. I do not know how to access the folder location for downloads or the wgt-private folder so I may download images to a client's watch and then use the downloaded version.

I'm sure my file is downloading as I've console logged on successful download and when I list the items in the directory the file shows up.

Placing downloads/[filename] or wgt-private/[filename] does not appear to work as these are virtual file locations however I've no idea how to access these files within the application without using the filesystem methods.

Download:

var download_obj = new tizen.DownloadRequest('someFile.svg', 'wgt-private');//Hidden the actual location however this file does display when enterting the whole file location

    tizen.download.start(download_obj, {
          onprogress: function(id, receivedSize, totalSize) {
            console.log(id);
            console.log(receivedSize);
            console.log(totalSize);
          },
          onpaused: function(id) {
            console.log(id);
          },
          oncanceled: function(id) {
            console.log(id);
          },
          oncompleted: function(id, fullPath) {
            console.log(id);
            console.log(fullPath);
          },
          onfailed: function(id, error) {
            console.log(id);
            console.log(JSON.stringify(error));
          }
        });

Full path comes out as: wgt-private/someFile.svg

Doesn't display as displays a file error in the console on all attempts.


Solution

  • I understand that your questions relates to how to show the image downloaded with tizen.download API in html img tag.

    I can see two workarounds that could help you with it:

    1. You can use filesystem API (which you would like to avoid), BUT since 5.0 there is a method which needs no additional privileges and I hope it will match your needs - FileSystemManager.toURI(). It just gets the path to file (returned by download API) and returns the full URI, able to be used in img.
    2. I noticed that download to non-public directories on the device, download API returns the 'hidden' path which uses virtual root, but when downloading to public directory as 'downloads', the full path is returned and it works for img as well.

    If both of above is not acceptable for you, I am afraid that the only alternative is to use regular tizen.filesystem API and resolve the path from download API and then use File.toURI() function to get the path.

    var link = "http://techslides.com/demos/samples/sample.jpg"
    var download_obj = new tizen.DownloadRequest(link, 'wgt-private');//Hidden the actual location however this file does display when enterting the whole file location
    
        tizen.download.start(download_obj, {
              oncompleted: function(id, fullPath) {
                console.log("completed " + id + " : " + fullPath);
                tizen.filesystem.resolve(fullPath, (s)=>{console.log("Resovled full path: " + s.toURI())}, (e) => {console.log(e)})
              },
              onfailed: function(id, error) {
                console.log("failed " + id);
                console.log(JSON.stringify(error));
              }
            });