Ionic Delete File using Native URL

安稳与你 提交于 2021-02-09 11:54:28

问题


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


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/47069764/ionic-delete-file-using-native-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!