I want to download images from my Ionic app into my phone’s gallery (android and ios, but testing on android).
A simple example is using Ionic’s own Build your First App. I basically want to take those photos that are displayed, and selectively download them to my phone’s gallery. I have tried Canvas2ImagePlugin (could not get to import) and Base64ToGallery but have gotten neither to work properly.
What would be your approach to this? Thanks.
Here is my current approach with Base64ToGallery:
const download_photo = async () => {
const base64Data = await base64FromPath(photoToDelete.webviewPath!);
Base64ToGallery.base64ToGallery(base64Data, {
prefix: "", // Not sure what this should be, already tried '_img', 'img_', 'data:image/jpeg;base64,'
mediaScanner: true,
}).then(
(res) => console.log("Saved image to gallery ", res),
(err) => console.log("Error saving image to gallery ", err)
);
};
download_photo();
Console logging the Base64Data shows it as:
“data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1B…” etc, with some foward slashes throughout.
I get these 2 errors in android debugging using base64ToGallery:
- “D/skia: — Failed to create image decoder with message ‘unimplemented’”
- “Msg: Error saving image to gallery The image could not be decoded”
Here’s the github. My main working file is src/pages/tab2.tsx
3 posts - 2 participants