[英]Sails.js how can i get the name of image after upload
我想獲取圖像的名稱,並在上傳后將其插入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(/^.[\\\\\\/]/, '')
覆蓋它?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.