Reputation: 2272
In an Ionic 3 app I have a photo gallery which displays images from an album. It works fine, but I can't delete an image.
A LibraryItem
, as retrieved by cordova.plugins.photoLibrary.getLibrary
looks like this:
creationDate: Sat Nov 04 2017 21:21:33 GMT-0400 (EDT)
fileName: "2017-10-5-1.jpg"
height: 960
id: "1937;/storage/emulated/0/Pictures/Timelapser/2017-10-5-1.jpg"
latitude: 0
longitude: 0
photoURL: "cdvphotolibrary://photo?photoId=1937%3B%2Fstorage%2Femulated%2F0%2FPictures%2FTimelapser%2F2017-10-5-1.jpg"
thumbnailURL: "cdvphotolibrary://thumbnail?photoId=1937%3B%2Fstorage%2Femulated%2F0%2FPictures%2FTimelapser%2F2017-10-5-1.jpg&width=512&height=384&quality=0.8"
width: 1280
I am trying to delete this (or any other) image file. However anything I try, Cordova throws an error and the file doesn't seem to exist. Ionic's manual is quite hazy at this point. This is all it says:
removeFile(path, fileName)
The parameters are pretty obvious, except what are they supposed to be? I tried everything, extracted path and filename from the photoURL
value, but nothing seems to help. Neither checkFile
nor removeFile
seems to find the file.
Upvotes: 2
Views: 1293
Reputation: 2735
You can not delete a file from the cdvphotolibrary:// url. If you want to delete a file, you need to have file:/// native url.
check the Getting native file location open issue with the PhotoLibary plugin.
AndreasGassmann has a fork that returns the native url also. As per him you can get the native urls:
Upvotes: 3