我正在尝试在节点js中上传图片。
我的用户路径代码是
var multer = require('multer');
var app = express();
var upload = multer({ dest: './uploads/'});
var dateFormat = require( 'dateformat' );
app.use( multer({ dest: './uploads/',
rename: function (fieldname, filename) {
return filename+Date.now();
},
onFileUploadStart: function (file) {
console.log(file.originalname + ' is starting ...');
},
onFileUploadComplete: function (file) {
console.log(file.fieldname + ' uploaded to ' + file.path)
}
}));
router.post( '/upload-picture', function( req, res, next ) {
upload(req,res,function(err) {
if(err) {
return res.end("Error uploading file.");
}
res.end("File is uploaded");
});
});
和上传文件夹只是回到routs文件夹的一步,与routs文件夹一起。
我文件已上传消息,但图片未上传到文件夹中。我在哪里做错了?