Skip to content

Commit 531e2ff

Browse files
committed
Merge pull request parse-community#604 from flovilmart/adds-max-file-size-option
Adds maxUploadSize option
2 parents b1c2d9d + 61e8f2a commit 531e2ff

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Routers/FilesRouter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Config from '../Config';
88

99
export class FilesRouter {
1010

11-
getExpressRouter() {
11+
getExpressRouter(options = {}) {
1212
var router = express.Router();
1313
router.get('/files/:appId/:filename', this.getHandler);
1414

@@ -19,7 +19,7 @@ export class FilesRouter {
1919

2020
router.post('/files/:filename',
2121
Middlewares.allowCrossDomain,
22-
BodyParser.raw({type: () => { return true; }, limit: '20mb'}), // Allow uploads without Content-Type, or with any Content-Type.
22+
BodyParser.raw({type: () => { return true; }, limit: options.maxUploadSize || '20mb'}), // Allow uploads without Content-Type, or with any Content-Type.
2323
Middlewares.handleParseHeaders,
2424
this.createHandler
2525
);

src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function ParseServer({
8383
enableAnonymousUsers = true,
8484
oauth = {},
8585
serverURL = '',
86+
maxUploadSize = '20mb'
8687
}) {
8788
if (!appId || !masterKey) {
8889
throw 'You must provide an appId and masterKey!';
@@ -147,14 +148,16 @@ function ParseServer({
147148
var api = express();
148149

149150
// File handling needs to be before default middlewares are applied
150-
api.use('/', new FilesRouter().getExpressRouter());
151+
api.use('/', new FilesRouter().getExpressRouter({
152+
maxUploadSize: maxUploadSize
153+
}));
151154

152155
// TODO: separate this from the regular ParseServer object
153156
if (process.env.TESTING == 1) {
154157
api.use('/', require('./testing-routes').router);
155158
}
156159

157-
api.use(bodyParser.json({ 'type': '*/*' }));
160+
api.use(bodyParser.json({ 'type': '*/*' , limit: maxUploadSize }));
158161
api.use(middlewares.allowCrossDomain);
159162
api.use(middlewares.allowMethodOverride);
160163
api.use(middlewares.handleParseHeaders);

0 commit comments

Comments
 (0)