NodeJS mySQL Insert Blob

后端 未结 4 1152
别跟我提以往
别跟我提以往 2020-12-20 17:03

I need a little help with NodeJS and MySQL blob insertion.

Here\'s the code snippet i\'m using

fs.open(temp_path, \'r\', function (status, fd) {
             


        
4条回答
  •  情话喂你
    2020-12-20 18:01

    For the small files, you can try below code:

    var fileInsertSQL = "insert ignore into File(id, content, creationTime) values(?,?,?)";
    db.query(fileInsertSQL, ["id1", fs.readFileSync(filepath), new Date().getTime()], function (err, dbRes) {
        if(err){
            console.error(err);
        } else {
            //Do something
        }
    })
    

提交回复
热议问题