简体   繁体   English

tizen.filesystem.resolve()错误-对象的内容不包含有效值

[英]tizen.filesystem.resolve() error - The content of an object does not include valid values

I am executing the following code in a Tizen web app I'm working on 我正在使用的Tizen网络应用程序中执行以下代码

tizen.filesystem.resolve('.',
function (dir) {
    dir.listFiles(
        function (files) {
            for (var i = 0; i < files.length; ++i)
                console.log('File : ' + files[i].name + '\nURL : ' + files[i].toURI() + '\n========');
            } )
},
function (err) { console.log('Error : ' + err.message); window.__error = err },
'r')

... and I am getting the following in the console ...并且我在控制台中得到以下内容

null
VM569:10 Error : The content of an object does not include valid values.

My question is , what's wrong with the code snippet above ? 我的问题是,上面的代码段怎么了? How am I supposed to invoke the Tizen filesystem API ? 我应该如何调用Tizen文件系统API?

Thanks in advance . 提前致谢 。

tizen.filesystem.resolve('.' tizen.filesystem.resolve('。'

Above, you are trying to resolve . 以上,您正在尝试解决. (root?) support for which is not required and probably you don't have an access to it. (root?)不需要支持,您可能无法访问它。

VM569:10 Error : The content of an object does not include valid values. VM569:10错误:对象的内容不包含有效值。

This also confirms my observation, from the docs: 这也从文档中证实了我的观察:

The ErrorCallback is launched with these error types: 使用以下错误类型启动ErrorCallback:

  • InvalidValuesError - If any of the input parameters contain an invalid value. InvalidValuesError-如果任何输入参数包含无效值。 For example, the mode is "w" for the read-only virtual roots (wgt-package and ringtones). 例如,对于只读虚拟根(wgt-package和铃声),模式为“ w”。

Try to use one of the supported locations: 尝试使用受支持的位置之一:

The list of root locations that must be supported by a compliant implementation are: 兼容实现必须支持的根目录列表为:

  • documents - The default folder in which text documents (such as pdf, doc...) are stored by default in a device. 文档 -默认情况下,文本文档(例如pdf,doc ...)存储在设备中的默认文件夹。 For example, in some platforms it corresponds to the "My Documents" folder. 例如,在某些平台上,它对应于“我的文档”文件夹。
  • images - The default folder in which still images, like pictures (in formats including jpg, gif, png, etc.), are stored in the device by default. images-默认文件夹,默认情况下,图片(例如jpg,gif,png等格式)存储在设备中。 For example, in some platforms it corresponds to the "My Images" folder. 例如,在某些平台上,它对应于“我的图像”文件夹。
  • music - The default folder in which sound clips (in formats including mp3, aac, etc.) are stored in the device by default. 音乐 -默认情况下,设备中存储声音片段(包括mp3,aac等格式)的默认文件夹。 For example, in some platforms it corresponds to the "My Music" folder. 例如,在某些平台上,它对应于“我的音乐”文件夹。
  • videos - The default folder in which video clips (in formats including avi, mp4, etc.) are stored in the device by default. 视频 -默认情况下,设备中存储视频剪辑(格式包括avi,mp4等)的默认文件夹。 For example, in some platforms it corresponds to the "My Videos" folder. 例如,在某些平台上,它对应于“我的视频”文件夹。
  • downloads - The default folder in which downloaded files (from sources including browser, e-mail client, etc.) are stored by default in the device. downloads-默认文件夹,默认情况下,已下载文件(来自包括浏览器,电子邮件客户端等的来源)存储在设备中。 For example, in some platforms it corresponds to the "Downloads" folder. 例如,在某些平台上,它对应于“下载”文件夹。 ringtones: The default folder in which ringtones (such as mp3, etc) are stored in the device. 铃声:设备中存储铃声(例如mp3等)的默认文件夹。 camera : The default folder in which pictures and videos taken by a device are stored. 照相机:存储设备拍摄的照片和视频的默认文件夹。
  • wgt-package - The read-only folder to which the content of a widget file is extracted. wgt-package-提取小部件文件内容的只读文件夹。
  • wgt-private - The private folder in which a widget stores its information. wgt-private-小部件在其中存储其信息的专用文件夹。 This folder must be accessible only to the same widget and other widgets or applications must not be able to access the stored information. 此文件夹必须只能由相同的窗口小部件访问,并且其他窗口小部件或应用程序必须不能访问存储的信息。
  • wgt-private-tmp - Temporary, the private folder in which a widget can store data that is available during a widget execution cycle. wgt-private-tmp-临时的,一个私有文件夹,窗口小部件可以在其中存储在窗口小部件执行周期内可用的数据。 Content of this folder can be removed from this directory when the widget is closed or the Web Runtime is restarted. 关闭窗口小部件或重新启动Web运行时时,可以从此目录中删除此文件夹的内容。 This folder must be accessible only to the same widget and other widgets or applications must not be able to access it. 此文件夹必须只能由相同的窗口小部件访问,并且其他窗口小部件或应用程序必须不能访问它。

See an example code from API ref. 请参阅API参考中的示例代码 site : 网站

var documentsDir;
function onsuccess(files) {
 for (var i = 0; i < files.length; i++) {
   console.log("File Name is " + files[i].name); // displays file name
 }

 var testFile = documentsDir.createFile("test.txt");

 if (testFile != null) {
   testFile.openStream(
     "w",
     function(fs) {
       fs.write("HelloWorld");
       fs.close();
     }, function(e) {
       console.log("Error " + e.message);
     }, "UTF-8"
   );
 }
}

function onerror(error) {
 console.log("The error " + error.message + " occurred when listing the files in the selected folder");
}

tizen.filesystem.resolve(
 'documents',
 function(dir) {
   documentsDir = dir;
   dir.listFiles(onsuccess, onerror);
 }, function(e) {
   console.log("Error" + e.message);
 }, "rw"
);

see, below FileSystem Tutorial and API Reference 请参见下面的FileSystem教程和API参考

FileSystem Tutorial https://developer.tizen.org/development/tutorials/web-application/tizen-features/base/filesystem#retrieve FileSystem教程https://developer.tizen.org/development/tutorials/web-application/tizen-features/base/filesystem#retrieve

Filesystem API Reference https://developer.tizen.org/dev-guide/latest/org.tizen.web.apireference/html/device_api/mobile/tizen/filesystem.html#FileSystemManager::resolve 文件系统API参考https://developer.tizen.org/dev-guide/latest/org.tizen.web.apireference/html/device_api/mobile/tizen/filesystem.html#FileSystemManager::resolve

If you put your text file on /project_root/data/text/x.txt. 如果将文本文件放在/project_root/data/text/x.txt上。 You can access to that file with "wgt-package/data/text/x.txt" path on webapi. 您可以在webapi上使用“ wgt-package / data / text / x.txt”路径访问该文件。

So below is simple example code. 因此,下面是简单的示例代码。 try it. 试试吧。

function onsuccess(files) {
   for (var i = 0; i < files.length; i++) {
     console.log("File Name is " + files[i].name); // displays file name

     if(file[i].name = "your_txt_file.txt"){
        //do something here. file[i].readAsText(....)
     }
   }
 }

 function onerror(error) {
   console.log("The error " + error.message + " occurred when listing the files in the selected folder");
 }

 tizen.filesystem.resolve(
     "wgt-package/data/text",
     function(dir) {
       documentsDir = dir; dir.listFiles(onsuccess,onerror);
     }, function(e) {
       console.log("Error" + e.message);
     }, "rw"
 );

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

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