Skip to content
Advertisement

Cordova SQLite save BLOB

I have a problem with Cordova SQLite plugin.

How can I save BLOB image to SQLite?

I have BLOB object in JS:

JavaScript

And I trying to save it

JavaScript

And when i trying to get this image:

JavaScript

I get this string:

JavaScript

How can i convert it to BLOB again?

Also i trying to save images in base64, but i can’t save big images to SQLite, because base64 string is very huge. (It’s works with small images)

Please, help me and sorry for my English.

Advertisement

Answer

You cannot save JavaScript Blob objects to the SQLite Plugin. It doesn’t support the Blob format. Yes I know it has a BLOB type, but confusingly it’s not the same thing. 🙂

WebSQL/SQLite Plugin does support binary strings as an alternative to Blobs. However, you may run into issues because there are numerous bugs in the implementation on both iOS and Android (some details are here).

In PouchDB we worked around these issues, so the attachment API abstracts everything away for you. Follow the PouchDB attachment guide and it will convert Blobs for you and store them in the database. To create a PouchDB that talks to the SQLite Plugin, you will need to do the following:

JavaScript

If you want to convert between Blobs and binary strings or a variety of other formats, check out blob-util.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement