如何解决将图片上传到mysql-Blob
我正在将前端的图像上传到mySql数据库中。
这是我的模特
const CheckIn = function (file) {
this.type = file.type;
this.name = file.name;
this.data = file.data;
};
CheckIn.create = (newCheckIn,result) => {
sql.query(`INSERT INTO files_checkin (type,name,data) VALUES (?,?,?)`,[newCheckIn.type,newCheckIn.name,newCheckIn.data],(err,res) => {
if (err) {
console.log("error: ",err);
result(err,null);
return;
}
console.log("created image: ",{
nr: res.insertId,...newCheckIn
});
result(null,...newCheckIn
});
});
};
还有我的控制器的一部分
exports.create = (req,res) => {
console.log("body " + JSON.stringify(req.body));
if (!req.body) {
res.status(400).send({
message: "Content can not be empty!"
});
}
const checkin = new CheckIn({
type: req.file.mimetype,name: req.file.originalname,data: req.file.buffer
});
CheckIn.create(checkin,data) => {
if (err)
res.status(500).send({
message: err.message || "Some error occurred while creating the Alias."
});
else res.send(data);
});
};
一切正常,直到我想上传例如5mb大小的图像为止。 然后我收到了loooooong blob,我的终端崩溃了。 看起来像矩阵。
我应该如何上传大块?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。