【发布时间】:2022-02-03 05:22:39
【问题描述】:
我正在从我的 SQL 数据库中获取数据,如下所示:
const mysql = require("mysql");
const connection = mysql.createConnection({
host: "localhost",
user: "root",
database: "database",
password : ''
});
//connection.release();
connection.connect(function(err) {
if (err) console.log(err);
});
connection.query("SELECT image FROM table WHERE id=(SELECT max(id) FROM table);", function (err, result, fields) {
if (err) console.log(err);
console.log(result);
});
/*Output:
[
RowDataPacket {
image: <Buffer 64 61 74 61 3a 69 6d 61 67 65 2f 6f 63 74 65 74 2d 73 74 72 65 61 6d 3b 62 61 73 65 36 34 2c 69 56 42 4f 52 77 30 4b 47 67 6f 41 41 41 41 4e 53 55 68 ... 27941 more bytes>
}
]
*/
如何在 Node.js 中将 result 转换为 base64 图像?例如:
'data:image/png;base64,iVBORw0KGgoAAAANS'
【问题讨论】:
标签: mysql sql node.js image base64