question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promises (await/async) support in Multer 2.0 (MulterError) instead of callback

See original GitHub issue

To 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:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pubmikebcommented, Aug 6, 2021

Well, then it’s a great opportunity to upgrade the entire Express.js codebase to make it ES2021 friendly.

1reaction
seahindenizcommented, Nov 16, 2020

Similar to #265?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found