我想在我的 sails.js 框架应用程序中集成 multer 文件上传包
有人能指导一下如何在 sails.js 中使用吗?
multer
https://www.npmjs.com/package/multer,但很遗憾它没有可用的教程。有人能指导一下如何在 sails.js 中使用吗?
multer
https://www.npmjs.com/package/multer,但很遗憾它没有可用的教程。var uploadFile = req.file('user_picture');
uploadFile.upload({ dirname: filePath }, function onUploadComplete(err, files) {
if (err) return res.serverError(err);
// IF ERROR Return and send 500 error
console.log(files);
});
< p > user_picture
是您表单中的变量名称。
希望这可以帮助您!
module.exports.http = {
middleware: {
/***************************************************************************
* *
* The order in which middleware should be run for HTTP requests. *
* (This Sails app's routes are handled by the "router" middleware below.) *
* *
***************************************************************************/
order: [
'cookieParser',
'session',
'fileMiddleware',
'bodyParser',
'compress',
'poweredBy',
'router',
'www',
'favicon',
],
/***************************************************************************
* *
* The body parser that will handle incoming multipart HTTP requests. *
* *
* https://sailsjs.com/config/http#?customizing-the-body-parser *
* *
***************************************************************************/
bodyParser: (function () {
const bodyParser = require('body-parser');
bodyParser.json();
bodyParser.urlencoded({ extended: true });
return bodyParser();
})(),
fileMiddleware: (function () {
const multer = require('multer');
const upload = multer();
return upload.fields([{ name: 'images' }, { name: 'profile' }, { name: 'cover' }]);
})(),
}
};