Reputation: 619
I'm trying to save a blob image into sqlite (Web SQL) on an Apache Cordova App which is run on Android.
I've figured out how to create the blob and obtain it from a local file. The problem is that on the database, instead of being saved the blob, saves an String which states [Object Blob]
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","http://localhost/image.jpg",true);
xmlhttp.responseType = 'blob';
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState==4){
var product_image = xmlhttp.response;
db.transaction(tx.executeSql("INSERT INTO scans(product_image) VALUES (?)",[product_image]), errorCB);
}
}
xmlhttp.send();
In fact, product_image returns a jpeg blob object. But as stated before, when I do SELECT the result returns [Object Blob]
This is how I create the database:
CREATE TABLE IF NOT EXISTS scans(id INTEGER PRIMARY KEY, product_image BLOB)
Upvotes: 1
Views: 1655
Reputation: 180172
WebSQL does not support binary data directly.
Typically, binary data is converted into some text format like Base64, and stored as text in the database.
Alternatively, use blob literals and the hex() function to treat blob values as hex strings at the interface between SQL and JavaScript.
Upvotes: 2