Any other way to convert image URL to base64 or blob? I want to store 900 images in sqlite database in cordova App for use it in offline mode. All images are in HD so I can't convert using canvas. Then I tried XMLHttpRequest but it takes a lots of time to convert in base64. So can anyone give you other solution to store image in database. Thanks in advance.
1 Answer
Whatever you are doing try to avoid this much HD images.
Just enumerating the concepts mentioned in comments:
- Cache images with
Application Cacheand save theURIs in database. - Convert all images to
base64manually and store them inJSONin server, client can now just access these staticJSONfrom server. Think of splitting them to chunks of 2-3 images/JSON. - Create an
APIthat would reply withbase64of requested images. TheAPIwould fetch the image just in time, calculate thebase64and reply withJSONcontaining thebase64as string.
1 Comment
jungerislaender
I'd highly recommend #1 and use image compression beforehand.
~900MB?) in mobile doesn't sound like a good thing, you probably have to rethink about this requirement, especially when offline databases doesn't offer too much MBs. Even if you want to cache I would recommend usingApplication Cacheinstead ofwebSQL.api/base64/20/30would return a JSON withbase64of 20th to 30th image.PS: This indeed looks like a XY Problem