Storing a photo in sqlite

Hi,

Is it possible to store a picture in a sqlite db? like it can be done in mysql using a ‚blob‘ variable?

Thank you very much

  1. Do you really need to do this? Can you simply provide a file path to the photo?
  2. If you want your database to be portable, e.g. you want to export it to other devices "with the images"

  • You can convert your photo to a byte array and store the blob, ensuring you have a BLOB data type.
  • Convert the photo to base64, then store in a suitable (large enough varchar) TEXT data type

You can use the SAF extension to convert a file to a byte array, and there are several base64 extensions for converting files to base64 string. I would suggest some resizing/cropping of images before storage to keep db size down, and speed up recovery.

Grat answer, TIMAI2

Good solution. I will try.
I want to do this, because I want a compact file something.db which contains really all data and can be lsaved easily andö stored.

Hello,

I only have the filename and want to convert the picture behind it to
kio4_base641. To store the data in the database.

How should I manage this?

Here, for example, I use the "direct" block, to convert an image in the assets to base64 (using companion app):

You can then set this and the filename to fields in a record in your sqlite table

Thank You very much, TIMAI2.

I see. Like you said, I should not do this. My phone, 6 Cores 8 GB of RAM. Doesn‘t have enough power to manage this.

Thank You again. Everything you told me, was perfect and working, but the time doesn‘t seem to be ripe for the things, I liked to do. I will store the photos in a file and compress them together with the db to make it easier to handle the backup procedure.

Surprising...

Did you try resizing the images (e.g. a camera image will be between 4-8mb, resizing to suit a view on the phone (e.g. 640x480) would get your file size down to kB). Base64 strings are generally 1.3x the size of the file size.

ImageConvertor extension