Helo..
I'm new in phonegap..
I had a problem to delete file in android phonegap 3.4
console.log(photo);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
photo, {create: false},
function gotFileEntry(fileEntry) {
fileEntry.remove();
},
onError);
},
onError);
Log Result
04-24 16:29:54.234: I/Web Console(16213): file:///storage/sdcard0/DCIM/Camera/1398331773136.jpg
04-24 16:49:01.989: W/System.err(18864): org.apache.cordova.file.EncodingException: This path has an invalid ":" in it.
04-24 16:49:01.994: W/System.err(18864): at org.apache.cordova.file.LocalFilesystem.getFileForLocalURL(LocalFilesystem.java:159)
04-24 16:49:01.994: W/System.err(18864): at org.apache.cordova.file.FileUtils.getFile(FileUtils.java:698)
04-24 16:49:03.664: I/Web Console(18864): 5
after search, i got this (List of Error Codes and Meanings) in doc
5 = ENCODING_ERR
is file path is wrong and how to get valid path to file in sdcard ?
Thanks
I think your problem is in the way you are calling to the callback functions. This code is working for me:
console.log("remove file");
var relativeFilePath = "MyDir/file_name.png";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
fileSystem.root.getFile(relativeFilePath, {create:false}, function(fileEntry){
fileEntry.remove(function(file){
console.log("File removed!");
},function(){
console.log("error deleting the file " + error.code);
});
},function(){
console.log("file does not exist");
});
},function(evt){
console.log(evt.target.error.code);
});
The simplest way to access an absolute path starting with file://
is by using window.resolveLocalFileSystemURL()
var url = "file:///storage/emulated/0/Android/data/myPackageName/cache/1461244585881.jpg";
window.resolveLocalFileSystemURL(url, function(file) {
file.remove(function(){
console.log(url + " deleted");
},onError);
}, onError);
additional helpful links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With