4

I want to use image storage on DB and not URL.

On my server side I use PostgreSQL and I read here that "bytea" is the suggested format to use in order to store files.

On my mobile app side, the DB is SQLite. It seems the data storage suggested format there is "BLOB" as described here.

I wonder, and I could not clearly find so far, if there is any conversion to do from PostgreSQL's "bytea" to SQLite's "BLOB"?

nyluje
  • 3,573
  • 7
  • 37
  • 67

1 Answers1

4

Both bytea and BLOB are data types within the database for storing raw binary data. They aren't encodings, like base64 or the like, so there is no conversion to do per se.

However, in reality your application will handle this data in at least 5 forms:

  • a PostgreSQL bytea column
  • a variable in your server-side application (probably a string or byte-array)
  • a stream of data in the API that links your server to your client (possibly encoded in some ASCII-safe form such as base64)
  • a variable in your client-side mobile application
  • an SQLite BLOB column

The data will flow through each of these forms in turn, so the conversions you need to worry about are not PostgreSQL to SQLite, but PostgreSQL to/from server-side language, server-side language to/from API encoding, and so on. You shouldn't need to make any changes to your mobile app if you change your server to use MySQL, or store the data in separate files, or find a way of creating it on the fly; the two ends of the process are completely separated.

This will be as much about using the right functions as explicitly understanding the encoding, just as storing the file to disk might involve the program environment manipulating the data, but you'd just write file.put(data) or whatever.

IMSoP
  • 89,526
  • 13
  • 117
  • 169