feat: increase upload size limit (#962)

This commit is contained in:
Jérémy M
2023-07-27 18:07:38 +02:00
committed by GitHub
parent 58530be78b
commit e90f44bbfb
5 changed files with 30 additions and 3 deletions

View File

@ -51,6 +51,8 @@
"apollo-server-express": "^3.12.0",
"axios": "^1.4.0",
"bcrypt": "^5.1.0",
"body-parser": "^1.20.2",
"bytes": "^3.1.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"date-fns": "^2.30.0",
@ -82,6 +84,7 @@
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@types/bcrypt": "^5.0.0",
"@types/bytes": "^3.1.1",
"@types/date-fns": "^2.6.0",
"@types/express": "^4.17.13",
"@types/graphql-upload": "^8.0.12",

View File

@ -6,5 +6,6 @@ export const settings: Settings = {
'profile-picture': ['original'],
'workspace-logo': ['original'],
},
maxFileSize: '10MB',
},
};

View File

@ -9,5 +9,6 @@ export interface Settings {
imageCropSizes: {
[key in ValueOfFileFolder]?: ShortCropSize[];
};
maxFileSize: `${number}MB`;
};
}

View File

@ -1,10 +1,14 @@
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import * as bodyParser from 'body-parser';
import { graphqlUploadExpress } from 'graphql-upload';
import bytes from 'bytes';
import { AppModule } from './app.module';
import { settings } from './constants/settings';
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
cors: true,
@ -13,8 +17,21 @@ async function bootstrap() {
// Apply validation pipes globally
app.useGlobalPipes(new ValidationPipe());
app.use(bodyParser.json({ limit: settings.storage.maxFileSize }));
app.use(
bodyParser.urlencoded({
limit: settings.storage.maxFileSize,
extended: true,
}),
);
// Graphql file upload
app.use(graphqlUploadExpress());
app.use(
graphqlUploadExpress({
maxFieldSize: bytes(settings.storage.maxFileSize),
maxFiles: 10,
}),
);
await app.listen(3000);
}

View File

@ -2649,6 +2649,11 @@
"@types/connect" "*"
"@types/node" "*"
"@types/bytes@^3.1.1":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@types/bytes/-/bytes-3.1.1.tgz#67a876422e660dc4c10a27f3e5bcfbd5455f01d0"
integrity sha512-lOGyCnw+2JVPKU3wIV0srU0NyALwTBJlVSx5DfMQOFuuohA8y9S8orImpuIQikZ0uIQ8gehrRjxgQC1rLRi11w==
"@types/connect@*":
version "3.4.35"
resolved "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz"
@ -3853,7 +3858,7 @@ body-parser@1.20.1:
type-is "~1.6.18"
unpipe "1.0.0"
body-parser@1.20.2, body-parser@^1.19.0, body-parser@^1.20.0:
body-parser@1.20.2, body-parser@^1.19.0, body-parser@^1.20.0, body-parser@^1.20.2:
version "1.20.2"
resolved "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz"
integrity sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==
@ -3973,7 +3978,7 @@ busboy@^1.0.0:
dependencies:
streamsearch "^1.1.0"
bytes@3.1.2:
bytes@3.1.2, bytes@^3.1.2:
version "3.1.2"
resolved "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz"
integrity sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==