我希望得到图像的名称,并在上传后将其插入MySQL。结果我得到了商店图片路径。像MySQL上的E:\ work \ assets \ pic_items \ 98046f37-ac7a-42cc-996.png我上传后只需要图像名称。
我怎样才能做到这一点?
这是我的控制器
update: function (req, res){
var id = req.param('id');
var category_id = req.param('category_id');
var title = req.param('title');
var description = req.param('description');
var width = req.param('width');
var height = req.param('height');
var price = req.param('price');
var picture_path = req.param('picture_path');
console.log(id);
req.file('picture_path').upload({dirname: "../../assets/pic_items"},function (err, uploadedFiles){
if (err) {
return res.send(err);
}
console.log(uploadedFiles);
if (uploadedFiles.length === 0){
console.log(uploadedFiles);
return res.serverError('no file was uploaded');
}
picture_path = uploadedFiles[0].filename;
picture_path = uploadedFiles[0].fd.replace(/^.[\\\/]/, '');
Item.update({id:id},{category_id:parseInt(category_id),title:title, description:description, width:width, height:height, price:parseInt(price), picture_path:picture_path}).exec(function(err){
if(err){
console.log(err);
return res.send('life is suck');
}
res.redirect('/item');
});
});
},
picture_path = uploadedFiles[0].filename;
picture_path = uploadedFiles[0].fd.replace(/^.[\\\/]/, '');
我相信它是在uploadedFiles[0].filename
。你为什么用uploadedFiles[0].fd.replace(/^.[\\\/]/, '')
压倒它?