Promises (await/async) support in Multer 2.0 (MulterError) instead of callback
See original GitHub issueTo control a size of an uploading files in Multer 2.0.0-rc.2 we can use:
const upload = multer({
limits: {
fileSize: CONFIG_STORAGE.uploader.maxFileSizeInBytes
}
}).single("file");
app.post('/upload', (req, res) => {
upload(req, res, (err) => {
if (err) {
console.error("An error occurred when uploading");
return;
}
console.log("Everything went fine");
});
})
It does work but it uses a callback and it’s ugly, especially in 2020+.
Isn’t better to provide a native promises (aka await
/async
) support instead?
Without applying a workaround such as util/promisify
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Node.js: Multer upload with promise? - Stack Overflow
It converts a callback-based function to a Promise-based one. ... same with async/await (async () => { await waitPromisified(2 * 1000); ...
Read more >How to upload files in NodeJS using Multer 2.0! - picnature
How to upload files in NodeJS using Multer 2.0! ... Multer is a middleware for node.js that handles multipart/form-data , and its getting...
Read more >Converting callbacks to promises - node js tutorial - YouTube
This video is very quick and short. In this video you are going to learn how to convert callback into promises and then...
Read more >How to send a File from React to NodeJS with Multer 2.0 ...
Multer 2.0.0 will be out soon! Learn how to send a file from your react frontend and parse it using the new Stream-based...
Read more >Rewrite Promise using async / await - JavaScript
Hi, can anyone help me rewrite this function using async / await instead of a Promise? function uploadToS3(req, res) { req.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, then it’s a great opportunity to upgrade the entire Express.js codebase to make it ES2021 friendly.
Similar to #265?