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?
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.
-
var imageFile = Titanium.Filesystem.getFile('myphoto.jpg');
var oneImage = imageFile.read();db.execute("INSERT INTO pics (id,image) VALUES(?,?)", 1, oneImage);