DEV Community

Mude Shoban Babu
Mude Shoban Babu

Posted on

File upload issue in Chrome browser using exceljs with size more than 400kb

Hello all,

I am facing few issues in Rest Service with file upload using exceljs and @nestjs/common(UploadedFile).

An Excel file size of 6mb is giving issue in Mozilla Firefox **and **Google Chrome, it takes too long time to upload and gives below error (Issue)
"502 Bad Gateway: Registered endpoint failed to handle the request"

When I am uploading non Excel file(other than Excel file, ex: docx) of any size in Mozilla Firefox, no issues are coming, it giving me INVALID_FILE_FORMAT error, which is right (No issues)

But When i upload a docx of more than 400kb in Google Chrome, no error coming and code is coming out of execution, actually it should give INVALID_FILE_FORMAT error.(issue)

Dependency versions:
"@nestjs/common": "8.2.3"
"@nestjs/platform-express": "8.2.3",
"exceljs": "4.3.0",

Code is below:
//code
@UseInterceptors(
FileInterceptor("file", {
storage: memoryStorage(),
fileFilter: excelFileFilter,
limits: {
fieldSize: 5 * 1024,
fileSize: 8000000,
},
})
)
@post("uploadFile")
@httpcode(200)
public async processExcelUpload(
@uploadedfile() file: Express.Multer.File
): Promise {

//this code dont have any issues
const workbook: Excel.Workbook = new Excel.Workbook();

const wb: Excel.Workbook = await workbook.xlsx.load(file.buffer);
const worksheet: Excel.Worksheet = wb.worksheets[0];

.....etc..
}

Here is the excelFileFilter code:

export const excelFileFilter = (
req: Request,
file: Express.Multer.File,
cb: (ex: HttpException, bool: boolean) => void
): void => {
if (!allowedMimeTypesExcel.includes(file.mimetype)) {
return cb(
new HttpException("INVALID_FILE_FORMAT", 400),
false
);
}
return cb(null, true);
};

Please let me know if anyone facing same issue and what is the solution for the same. Many thanks in advance ~Shoban.

Top comments (0)