小编Bar*_*nni的帖子

如何更改Sails JS中间件的默认配置

我试图改变Sails JS应用程序的设置,并且有点麻烦将参数传递给body-Parser以更改默认设置.

我之前有这里描述的问题:发布更大的文件

我相信通过更改默认的'limit'选项可以正确回答这个问题,因为100kb的默认大小减去formData对象的33%开销与我能够/不能发送的文件大小非常一致.所以提出的解决方案是这样的:

var bodyParser = require('body-parser');
...
app.use(bodyParser.urlencoded( { limit: 1048576 } )); 
Run Code Online (Sandbox Code Playgroud)

但我无法在我的Sails应用程序中实现该解决方案.我已经阅读了关于更改中间件设置的Sails文档,并在我的config/http.js文件中尝试了以下内容...

第一次尝试 - 包装

/**
 * HTTP Server Settings
 * (sails.config.http)
 */

module.exports.http = {

middleware: {

  order: [
   'startRequestTimer',
   'cookieParser',
   'session',
   'refreshSessionCookie',
   'bodyParserInit',
   'bodyParser',
   'handleBodyParserError',
   'compress',
   'methodOverride',
   'poweredBy',
   '$custom',
   'requestLogger',
   'router',
   'www',
   'favicon',
   '404',
   '500'
  ],

   bodyParserInit   : (function (){
     let bodyParser = require('body-parser');

     return bodyParser( { extended: true, limit: 1073741824 } )
   })(),

  )
},

// cache: 31557600000 …
Run Code Online (Sandbox Code Playgroud)

javascript middleware node.js sails.js body-parser

6
推荐指数
1
解决办法
163
查看次数

$http.post:大文件不起作用

我正在尝试使用以下代码通过我的网络应用程序上传文件。

看法:

  <form name="uploadForm" class="form-horizontal col-sm-12">
    <div class="col-sm-4">
      <input type="file" ng-model="rsdCtrl.viewData.file" name="file"/>
    </div>
    <div class="col-sm-4">
      <button class="btn btn-success" type="submit" ng-click="uploadFile()">Upload</button>
    </div>
  </form>
Run Code Online (Sandbox Code Playgroud)

控制器:

function uploadFile(){
  if (uploadForm.file.$valid && file) {
    return uploadService.upload(vd.file, "Convictions Calculator", "PCCS").then(function(response){
      /* Some stuff */
    }).catch(handleServiceError);
  }
}
Run Code Online (Sandbox Code Playgroud)

上传服务:

(function (){
'use strict';
angular.module('cica.common').service('uploadService', ['$http', '$routeParams', uploadService]);

function uploadService($http, $routeParams) {

    this.upload = function (file, name, type) {
        const fd = new FormData();
        fd.append('document', file);
        fd.append('jobId', $routeParams.jobId);
        fd.append('documentRename', name);
        fd.append('documentType', type);

        return $http.post('/document/upload', fd, {
            transformRequest: …
Run Code Online (Sandbox Code Playgroud)

node.js express angularjs body-parser ng-file-upload

5
推荐指数
1
解决办法
6892
查看次数