node.js:在sails.js中使用multer上传文件

我想在我的sails.js框架应用程序中集成multer
https://www.npmjs.com/package/multer文件上传软件包,遗憾的是没有可用的教程.

任何人都可以指导如何在sails.js中做到这一点?

最佳答案

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' }]);
    })(),
  }
};

你可以试试这个.它将覆盖船长.

点赞