Bik
Bik

Reputation: 553

Ionic Delete File using Native URL

I am using CSDK image editor to edit the image. Here is the method to edit the image:-

CSDKImageEditor.edit(success, error, imageUrl, options);

So on success method editor is returning the image url, that's in native format like:-

content://media/23

I need to delete that file after editing. So I am using Cordova File to delete the file. As this is native url so cordova file can't find the file using that url. After going through google I got a plugin Corodva Filepath to convert native url to file url, But this plugin is not working. After installing the plugin I can't build the file.

So the question is, I need to delete the file and I don't have file url, I have only Native url. Please suggest me something so I can delete the file using native url or I can convert the Native Url to file url in Ionic1

Upvotes: 3

Views: 3891

Answers (2)

Bikash Mondal
Bikash Mondal

Reputation: 44

I had same problem with Filepath Plugin. All I had just removed the last commit and It's working fine. On last commit only permission has been added, so I don't think it will affect your app.

Upvotes: 1

Maxim Shoustin
Maxim Shoustin

Reputation: 77930

Hybrid applications do not have direct access to file System. This is a reason why you cannot use content://media/23.

You can use cordova-plugin-file by Apache to access to file and this Post how to delete it:

var path = "file:///storage/emulated/0";
var filename = "myfile.txt";

window.resolveLocalFileSystemURL(path, function(dir) {
    dir.getFile(filename, {create:false}, function(fileEntry) {
              fileEntry.remove(function(){
                  // The file has been removed succesfully
              },function(error){
                  // Error deleting the file
              },function(){
                 // The file doesn't exist
              });
    });
}); 

Upvotes: 6

Related Questions