Problems with storing an image in SQLite and reload it

You must Login before you can answer or comment on any questions.

Hi, i store my captured image in the database in a BLOB field. On the success-Event of my camera i get the image with e.media. The length of this blob is e.g. 5000. Now I store the data in the database with

var sql = 'UPDATE XXX SET IMAGE = ? WHERE ID = 1'
db.execute(sql, emedia);
When i reload the data, the length is only e.g. 5
var rs = db.execute('SELECT IMAGE FROM XXX WHERE ID = 1');
var image = rs.fieldByName('IMAGE');
Ti.API.info(image.length);
What I'm doing wrong? I want to achieve to store my image in the database and reload it to show it in an imageview. I'm using the latest Titanium SDK.

2 Answers

Accepted Answer

Someone else may be able to shed more light on why this isn't working, but I'd recommend storing the file on the file system and just storing a pointer to it in the database. I tried storing images in the database over a year ago (v1.5) and never got it to work properly.

It is a bit more overhead to handle CRUD operations but it works great.

— answered 7 months ago by Jeff Bonnes
answer permalink
2 Comments
  • I think there is no more information necessary, is it? I want to store my image data as blob ande load it as blob and display in an imageview. I think its possible when i encode it before saving as base64 and decode before loading. This is my workaround at the moment

    — commented 7 months ago by Alexander Stark

  • Save data as bse64 encodes does the trick

    — commented 7 months ago by Alexander Stark

Your Answer

Think you can help? Login to answer this question!