Question

I've got similar code as shown below where when the user presses the load button they get the pick UI and can press and image then it gets displayed. However I'm struggling with a delete button, I want to use the pick UI again and just change the onsuccess part, I've been experimenting with what it says here https://developer.mozilla.org/en/docs/WebAPI/Device_Storage#Delete_a_file but I can't get it to delete the image I choose.

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");
          }
        };
    }
}
Was it helpful?

Solution

I got this to work with a success function like the following:

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

I also had the following in my manifest:

"permissions": {
   "device-storage:sdcard": {
     "access": "readwrite"
   },
   "device-storage:pictures": {
     "access": "readwrite"
   }
},
"type": "privileged"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top