mozilla / r2d2b2g

Firefox OS Simulator is a test environment for Firefox OS. Use it to test your apps in a Firefox OS-like environment that looks and feels like a mobile phone.
https://addons.mozilla.org/en-US/firefox/addon/firefox-os-simulator/
Other
392 stars 139 forks source link

Enumerating of files on sdcard #897

Closed nazar-pc closed 10 years ago

nazar-pc commented 10 years ago

I'm using snippet from this article: https://developer.mozilla.org/en-US/docs/Web/API/DeviceStorage.enumerate

var sdcard = navigator.getDeviceStorage('sdcard');

// Let's retrieve files from last week.
var param = {
  since: new Date((+new Date()) - 7*24*60*60*1000)
}

var cursor = sdcard.enumerate(param);

cursor.onsuccess = function () {

  if (this.result) {
    var file = this.result;
    console.log("File updated on: " + file.lastModifiedDate);

    // Once we found a file we check if there are other results
    // Then we move to the next result, which calls the cursor
    // success possibly with the next file as result.
    this.continue();
  }
}

cursor.onerror = function () {
    console.log(this.error.name);
};

But get error "TypeMismatchError" with 1.4 and 2.1 versions of simulator. Sorry if this is a stupid question, I only want to get list of files and directories, and reading a lot of articles I still can't do that.

If use music instead of sdcard everything works fine.

Permissions in manifest:

...
    "permissions" : {
        "device-storage:music"  : {
            "description" : "Music",
            "access"      : "readonly"
        },
        "device-storage:sdcard" : {
            "description" : "SDCard",
            "access"      : "readonly"
        },
        "storage"               : {
            "description" : "Storage"
        }
    },
...
jryans commented 10 years ago

The SD card doesn't have very nice support in the simulator at the moment.

Read this bug to follow the current state. If you create the fake-sdcard directory that the bug mentions and add some file, does it work then?

nazar-pc commented 10 years ago

Yes, creation of fake-sdcard works! But how to enumerate directories? I need basic natural features to work with file system.

jryans commented 10 years ago

The docs I can find about the Device Storage API suggests to me that it does not support nested directories, only a flat list of files per storage area. However, I am not sure. Try the #openwebapps room on Mozilla IRC, or the dev-webapps mailing list for more info.