Loopbackjs 将文件数据上载到mysql blob类型
我正在使用Strongloop应用程序将图像上传到mysql数据库 我正在尝试将图像存储到mysql blob列中。Loopbackjs 将文件数据上载到mysql blob类型,loopbackjs,strongloop,node-mysql,Loopbackjs,Strongloop,Node Mysql,我正在使用Strongloop应用程序将图像上传到mysql数据库 我正在尝试将图像存储到mysql blob列中。 我对该列的模型配置如下: "data": { "type": "Buffer", "mysql": { "columnName": "data", "dataType": "blob", "dataLength": null } } MySql列的类型
我对该列的模型配置如下:
"data": {
"type": "Buffer",
"mysql": {
"columnName": "data",
"dataType": "blob",
"dataLength": null
}
}
MySql列的类型为“blob”
我尝试使用“强大”存储数据:var form = new formidable.IncomingForm({
keepExtensions: true
});
form.parse(req, function(err, fields, files) {
var readData = fs.readFileSync(files.file.path);
if(!Buffer.isBuffer(readData)){
readData = new Buffer(readData);
}
var input = {
id: '',
name: files.file.name,
type: files.file.type,
data: readData
};
<My-Model>.create(input, function(err, data1){
if(err){
res.status(500).send(err);
}
res.send(data1);
});
});
var form=new.IncomingForm({
keepExtensions:正确
});
解析(请求、函数(错误、字段、文件){
var readData=fs.readFileSync(files.file.path);
如果(!Buffer.isBuffer(readData)){
readData=新缓冲区(readData);
}
变量输入={
id:“”,
名称:files.file.name,
类型:files.file.type,
数据:readData
};
.创建(输入,函数(错误,数据1){
如果(错误){
资源状态(500)。发送(错误);
}
res.send(数据1);
});
});
我在创建回调时出错:消息:“ER_DATA_过长:第1行'DATA'列的数据过长”
sqlState:“22001”
看起来创建API在内部将“输入”视为字符串。使用调试字符串运行服务器。
set debug=loopback:connector:mysql&&node。
获取更多信息()