简体   繁体   English

如何使用Tizen Web studio在应用程序中使用下载的svg文件?

[英]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. 我可以下载SVG文件,此外,可以像通常在图像标签中那样显示svg文件。 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. 我不知道如何访问要下载的文件夹位置或wgt-private文件夹,因此我可以将图像下载到客户的手表上,然后使用下载的版本。

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. 放置downloads / [filename]或wgt-private / [filename]似乎不起作用,因为它们是虚拟文件位置,但是我不知道如何在不使用文件系统方法的情况下访问应用程序中的这些文件。

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 完整路径显示为:wgt-private / someFile.svg

Doesn't display as displays a file error in the console on all attempts. 在所有尝试中,“不显示为”都会在控制台中显示文件错误。

I understand that your questions relates to how to show the image downloaded with tizen.download API in html img tag. 我们了解您的问题与如何显示html img标签中使用tizen.download API下载的图像有关。

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() . 您可以使用文件系统API(要避免),但是从5.0开始,有一种方法不需要其他特权,我希望它可以满足您的需求-FileSystemManager.toURI() It just gets the path to file (returned by download API) and returns the full URI, able to be used in img . 它只是获取文件的路径(由下载API返回)并返回完整的URI,可以在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. 我注意到下载到设备上的非公共目录,下载API返回使用虚拟根目录的“隐藏”路径,但是当下载为“下载”到公共目录时,将返回完整路径,并且也适用于img

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. 如果以上两种情况都不适合您,那么恐怕唯一的选择是使用常规的tizen.filesystem API,并从download API解析路径,然后使用File.toURI()函数获取路径。

 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)); } }); 

You can find the proper web sample app: new Tizen project - Sample - Mobile 4.0 - Web application - Content - Download Manager 您可以找到合适的Web示例应用程序:新的Tizen项目-示例-移动4.0-Web应用程序-内容- 下载管理器

Open index.html and replace https://www.sample-videos.com/video/mkv/720/big_buck_bunny_720p_10mb.mkv with your file address. 打开index.html,并将https://www.sample-videos.com/video/mkv/720/big_buck_bunny_720p_10mb.mkv替换为您的文件地址。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM