I’m currently working on a NestJS application where I have a controller responsible for uploading files to BunnyCDN. The function used for the upload accepts a file path and buffer. However, I’m encountering an issue when trying to upload a file with a size of 13MB. The error message I receive is as follows:
ERROR [ExceptionsHandler] Request body larger than maxBodyLength limit
Error [ERR_FR_MAX_BODY_LENGTH_EXCEEDED]: Request body larger than maxBodyLength limit
My controller :
@Post('upload/file')
@UseInterceptors(
FileInterceptor('file')
)
async upload(@UploadedFile() file): Promise<string> {
let filePath: string = ''
const folderPath = 'programme/images'; // upload path in bunny
if (file) {
const { buffer } = file;
const currentDate = new Date().toISOString().replace(/[^a-zA-Z0-9]/g, '_').split('T')[0];
const currentTime = new Date().toISOString().split('T')[1].replace(/..+/, '').replace(/:/g, '');
const originalName = file.originalname.replace(/[^a-zA-Z0-9.]/g, '_').replace(/ /g, '_');
const randomName = `${currentDate}_${currentTime}_${originalName}`;
filePath = `${folderPath}/${randomName}`;
await this.bunnyCDNService.uploadFile(filePath, buffer);
}
return filePath;
}
I’ve already attempted to increase the request body size limit using the body-parser middleware in my NestJS application with the following configuration:
app.use(json({ limit: '50mb' }));
Could someone please guide me on how to effectively increase the request body size limit in NestJS for file uploads