terikon / cordova-plugin-photo-library

Maintainer needed. Please contact if you're using this library in your project
MIT License
149 stars 295 forks source link

How can we convert cdvphotolibrary to file:// #103

Open Anil8753 opened 6 years ago

Anil8753 commented 6 years ago

I have a requirement to delete a photo also. Is there any way to delete the photo from cdvphotolibrary path or I need to convert cdvphotolibary path to file:\. But I did not find the way to this conversion.

nandanshanubhag commented 6 years ago

I also needed the same functionality. in Android it works fine, but in iOS it complains that it cannot display the image so is there any way to get the file:// url of the stored images thanks

AndreasGassmann commented 6 years ago

This is currently not possible. You will have to change how the plugin works. I made some changes in my fork to get a photo with the file:// url, but it internally creates a copy, so it's not exactly what you are looking for. Maybe you can take my solution and change it a bit so it fits your needs.

soulmecca commented 6 years ago

Hello, @AndreasGassmann I also need to convert cdvphotolibrary to file:// to show photos from photo library with . Could you share how you did it and do you experience any performance drop by doing that?

What I need to do is showing thumbnails from cordova.plugins.photoLibrary.getLibrary function and then bring up the selected photos from it. I cannot currently find a way to present photos from cdvphotolibray on my iPhone with the Ionic app.

Thanks for any help!

AndreasGassmann commented 6 years ago

Hi @soulmecca. My code is available in my fork: https://github.com/AndreasGassmann/cordova-plugin-photo-library/tree/nativeFileUrls

Are you using WKWebView? Because if you don't then you can also just display it using cdvphotolibrary:// as described in the docs. I haven't migrated my app to WKWebView, so I'm still using the cdvphotolibrary-way and don't know how the performance will be. But I'd love to hear what you find out!

BrentonWatt commented 6 years ago

It's not really a fix but a kind of work around. I was saving the images directories to a SQLiteDB so with the WKWebview change I could no longer display my images so what I instead did is save the image ID provided in the saveImage() return object in photo-library, then when I need to use that image I use the getPhoto() call and pass the saved ID and then returns blob data, I then convert that blob data to base64 and use that for my image source.

I'm aware it's not suitable for everyone's needs but I thought of posting here in case it could help someone.

flogr commented 6 years ago

@BrentonWatt this is a nice way to display the images but you need native file urls to handle basic library functionalities like deleting or sharing images. And thats what most of the people here need, i think. And other workarounds that are based on temporary copies of the pics are dirty hacks, too.

rcrodrigues commented 5 years ago

@Anil8753 have you managed to make the deletion work fine?