Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Image encoding and Decoding - for updation of image in MYSQL database?

I need to upload the image in Mysql database, i use the following code,

var file = Ti.Filesystem.getFile('KS_nav_ui.png');
var blob1 = file.read();
var base64=Ti.Utils.base64encode(test);

in database it was updated as blob file with 4bytes as size,
when i fetch the element and decode using Ti.Utils.base64decode , it return nothing , database update with some data.

i need a solution to upload/download an image in Mysql database ?

also suggest some data type for storing image in database?

— asked October 8th 2010 by Karthikeyan Chandran
  • android
  • decode
  • decoding
  • encode
  • encoding
  • ios
  • iphone
  • titanium

2 Answers

  • Can't you just insert a row in a database table with an auto increment field (id), use that id for the name of your picture in the filesystem and load then the picture from that file system?

    As far as I understand you wouldn't this be too much effort.

    — answered October 8th 2010 by Peter Griffin
  • var imageFile = Titanium.Filesystem.getFile('myphoto.jpg');
    var oneImage = imageFile.read();

    db.execute("INSERT INTO pics (id,image) VALUES(?,?)", 1, oneImage);

    — answered December 19th 2010 by Mark Henderson
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.