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

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

我正在我正在开发的 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')

...我在控制台中得到以下信息

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

我的问题是,上面的代码片段有什么问题?我应该如何调用 Tizen 文件系统 API ?

提前致谢。

tizen.filesystem.resolve('.'

以上,您正在尝试解决不需要的 .(root?)支持,并且您可能无权访问它。

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

这也证实了我的观察,来自文档:

The ErrorCallback is launched with these error types:

  • InvalidValuesError - If any of the input parameters contain an invalid value. For example, the mode is "w" for the read-only virtual roots (wgt-package and ringtones).

尝试使用支持的位置之一:

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. 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. 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. 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. 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. 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. 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-private - The private folder in which a widget stores its information. 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. Content of this folder can be removed from this directory when the widget is closed or the Web Runtime is restarted. This folder must be accessible only to the same widget and other widgets or applications must not be able to access it.

查看来自 API ref. 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"
);

参见下面的文件系统教程和 API 参考资料

文件系统教程https://developer.tizen.org/development/tutorials/web-application/tizen-features/base/filesystem#retrieve

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

如果您将文本文件放在 /project_root/data/text/x.txt 上。您可以在 webapi 上使用 "wgt-package/data/text/x.txt" 路径访问该文件。

所以下面是简单的示例代码。试试吧。

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