You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to insert a buffer into a binary field (BLOB in MySQL), in /lib/utils.js prepareValue function, the buffer is treated as an object and is stringified (json.stringify()) and so data in the buffer is lost.
I think the buffer type should be handled inside utils.prepareValue() function.
I tried to read an image from disk, create a buffer of by the image bytes, save it in the database and then get it back from the database and write it. The result file is corrupted.
Suggested solution is to add a test on the object in the prepareValue function, if it's a buffer only escape it.
//Suggested Solution in /lib/utils.prepareValue() if(Buffer.isBuffer(value))returnmysql.escape(value);//This is my test codevarfs=require('fs');varbuffer=fs.readFileSync('/tmp/test/test.jpg')attachment.create({id : 20001,data : buffer}).exec(function(err,res){console.log(err||'-#success');attachment.findOne().where({id:20001}).exec(function(err,res){if(!err){fs.writeFile('/tmp/test/result.jpg',res.data,function(err){if(err){console.log(err);}else{console.log("The file was saved!");}});}});});//result.jpg is corrupted//This is my Model :{"identity": "attachment","tableName": "attachment","attributes": {"id": {"type": "integer","primaryKey": true},"data": {"type": "binary"}}}
The text was updated successfully, but these errors were encountered:
I'm trying to insert a buffer into a binary field (BLOB in MySQL), in /lib/utils.js prepareValue function, the buffer is treated as an object and is stringified (json.stringify()) and so data in the buffer is lost.
I think the buffer type should be handled inside utils.prepareValue() function.
I tried to read an image from disk, create a buffer of by the image bytes, save it in the database and then get it back from the database and write it. The result file is corrupted.
Suggested solution is to add a test on the object in the prepareValue function, if it's a buffer only escape it.
The text was updated successfully, but these errors were encountered: