使用选择界面删除图像 - Firefox OS

时间:2014-04-11 22:23:27

标签: firefox-os

我有类似的代码,如下所示,当用户按下加载按钮时,他们会获得选择UI,然后按下并显示图像然后显示。然而,我正在努力使用删除按钮,我想再次使用选择UI,只是更改onsuccess部分,我一直在试验它在这里所说的https://developer.mozilla.org/en/docs/WebAPI/Device_Storage#Delete_a_file,但我无法让它删除我选择的图片。

var pickImage = document.querySelector("#delete-image");
if (pickImage) {
    pickImage.onclick = function () {
        var pick = new MozActivity({
            name: "pick",
            data: {
                type: ["image/png", "image/jpg", "image/jpeg"],
                nocrop: true
           }
        });

        pick.onsuccess = function () {
          var img = document.createElement("img");

          var request = img.delete("img");

          request.onsuccess = function () {
            console.log("File deleted");
          }

          request.onerror = function () {
            console.log("Unable to delete the file");
          }
        };
    }
}

1 个答案:

答案 0 :(得分:0)

我使用了以下成功函数:

pick.onsuccess = function () {

    var fname = this.result.blob.name;
    console.log( "File Name " + fname );
    var sdcard = navigator.getDeviceStorage('sdcard');          
    var request = sdcard.delete(fname);
    request.onsuccess = function () {
        alert("File deleted");
    }
    request.onerror = function () {
        alert("Unable to delete the file: " + this.error.name);
    }
 };
 pick.onerror = function () {

    alert("Can't view the image!");
 }; 

我的清单中也有以下内容:

"permissions": {
   "device-storage:sdcard": {
     "access": "readwrite"
   },
   "device-storage:pictures": {
     "access": "readwrite"
   }
},
"type": "privileged"