I am working on a project for work, Using Typescript and ExpressJs they use inversify-express-utils for the controllers for all their endpoints. I was given a task to add a file upload backend endpoint to ingest a file (csv, pdf, dat) that could be a few bytes to upwards of 100Mb.
I am looking for advice for a multipart file upload structure (AND EXAMPLES) that works with inversify-express-utils.
Is Multer still one of the better file upload middlewares for node? If so are there any examples on how to fold it into a inversify-express-utils controller? I could not find any during my search over the last hour. Perhaps my Google Foo is lacking.
Is there a better file upload middleware for node/typescript/express/inversify-express-utils? And if so are there any code examples on getting it to work?
Here is an example endpoint with a Multer upload in 'inversify' with 'inversify-express-utils'
import * as express from 'express';
import multer from 'multer';
import {
BaseHttpController,
controller
httpPost,
} from 'inversify-express-utils';
import { inject } from 'inversify';
const storage = multer.memoryStorage();
const upload = multer({
storage,
limits: { fileSize: 100 * 1024 * 1024 },
});
@controller('/v1')
export class v1Controller extends BaseHttpController {
constructor(){
super();
}
@httpPost('/', upload.single('file'))
private async upload(req: express.Request, res: express.Response) {
const { file, body } = req;
// Do what you will with the file contents as type Express.Multer.File type
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.