简体   繁体   中英

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.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 ?

Thanks in advance .

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.

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

This also confirms my observation, from the docs:

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).

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. 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.

See an example code from 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"
);

see, below FileSystem Tutorial and API Reference

FileSystem Tutorial 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

If you put your text file on /project_root/data/text/x.txt. You can access to that file with "wgt-package/data/text/x.txt" path on webapi.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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