From 61e8f2aeeae7422edf1c56898d3ceddeb867f5fd Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Tue, 23 Feb 2016 11:49:21 -0500 Subject: [PATCH] Adds maxUploadSize option --- src/Routers/FilesRouter.js | 4 ++-- src/index.js | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Routers/FilesRouter.js b/src/Routers/FilesRouter.js index 305c503934..653f85b3fc 100644 --- a/src/Routers/FilesRouter.js +++ b/src/Routers/FilesRouter.js @@ -8,7 +8,7 @@ import Config from '../Config'; export class FilesRouter { - getExpressRouter() { + getExpressRouter(options = {}) { var router = express.Router(); router.get('/files/:appId/:filename', this.getHandler); @@ -19,7 +19,7 @@ export class FilesRouter { router.post('/files/:filename', Middlewares.allowCrossDomain, - BodyParser.raw({type: () => { return true; }, limit: '20mb'}), // Allow uploads without Content-Type, or with any Content-Type. + BodyParser.raw({type: () => { return true; }, limit: options.maxUploadSize || '20mb'}), // Allow uploads without Content-Type, or with any Content-Type. Middlewares.handleParseHeaders, this.createHandler ); diff --git a/src/index.js b/src/index.js index fb8d29efed..38d6a04490 100644 --- a/src/index.js +++ b/src/index.js @@ -83,6 +83,7 @@ function ParseServer({ enableAnonymousUsers = true, oauth = {}, serverURL = '', + maxUploadSize = '20mb' }) { if (!appId || !masterKey) { throw 'You must provide an appId and masterKey!'; @@ -147,14 +148,16 @@ function ParseServer({ var api = express(); // File handling needs to be before default middlewares are applied - api.use('/', new FilesRouter().getExpressRouter()); + api.use('/', new FilesRouter().getExpressRouter({ + maxUploadSize: maxUploadSize + })); // TODO: separate this from the regular ParseServer object if (process.env.TESTING == 1) { api.use('/', require('./testing-routes').router); } - api.use(bodyParser.json({ 'type': '*/*' })); + api.use(bodyParser.json({ 'type': '*/*' , limit: maxUploadSize })); api.use(middlewares.allowCrossDomain); api.use(middlewares.allowMethodOverride); api.use(middlewares.handleParseHeaders);