将图片上传到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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...