【问题标题】:tizen.filesystem.resolve() error - The content of an object does not include valid valuestizen.filesystem.resolve() 错误 - 对象的内容不包含有效值
【发布时间】:2016-03-01 00:40:25
【问题描述】:

我正在我正在开发的 Tizen Web 应用程序中执行以下代码

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.

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

提前致谢。

【问题讨论】:

    标签: javascript tizen tizen-wearable-sdk tizen-web-app tizen-web-simulator


    【解决方案1】:

    tizen.filesystem.resolve('.'

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

    VM569:10 错误:对象的内容不包含有效值。

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

    ErrorCallback 以这些错误类型启动:

    • InvalidValuesError - 如果任何输入参数包含无效值。例如,只读虚拟根(wgt-package 和铃声)的模式为“w”。

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

    合规实现必须支持的根位置列表如下:

    • documents - 设备中默认存储文本文档(例如 pdf、doc...)的默认文件夹。例如,在某些平台上,它对应于“我的文档”文件夹。
    • images - 静态图像(如图片(格式包括 jpg、gif、png 等))默认存储在设备中的默认文件夹。例如,在某些平台上,它对应于“我的图片”文件夹。
    • music - 默认情况下,声音剪辑(格式包括 mp3、aac 等)存储在设备中的默认文件夹。例如,在某些平台上,它对应于“我的音乐”文件夹。
    • videos - 默认情况下,设备中存储视频剪辑(格式包括 avi、mp4 等)的默认文件夹。例如,在某些平台上,它对应于“我的视频”文件夹。
    • downloads - 默认情况下,下载文件(来自浏览器、电子邮件客户端等来源)存储在设备中的默认文件夹。例如,在某些平台上,它对应于“下载”文件夹。 铃声:设备中存储铃声(如 mp3 等)的默认文件夹。 camera :存储设备拍摄的照片和视频的默认文件夹。
    • wgt-package - 小部件文件内容提取到的只读文件夹。
    • wgt-private - 小部件存储其信息的私有文件夹。此文件夹必须只能由同一个小部件访问,其他小部件或应用程序不得访问存储的信息。
    • wgt-private-tmp - 临时的私有文件夹,小部件可以在其中存储在小部件执行周期中可用的数据。当小部件关闭或 Web 运行时重新启动时,可以从该目录中删除该文件夹的内容。此文件夹必须只能由同一个小部件访问,并且其他小部件或应用程序不得访问它。

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

    【讨论】:

    • 修复了上述问题。谢谢。
    • @OlemisLang 我得到了。未捕获的类型错误:无法读取未定义的属性“替换”。
    • @uday214125 我面临同样的问题。有什么解决办法吗?
    【解决方案2】:

    请参阅下面的文件系统教程和 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"
     );
    

    【讨论】:

      猜你喜欢
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多