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.

Can Multer work without being a middleware?

See original GitHub issue

Hello guys!

Has multer a function to upload the file only based on the request? I mean being a simple function without being a middleware function using next.

I would like to know if there is something like that to achieve this: graphql/express-graphql#123.

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
chanoncommented, Feb 22, 2017

I wanted to know the same thing and tried what @LinusU recommended and got the same error.

I went back to look at the usage in the readme which shows:

app.post('/profile', upload.single('avatar'), function (req, res, next) {
  // req.file is the `avatar` file
  // req.body will hold the text fields, if there were any
})

app.post('/photos/upload', upload.array('photos', 12), function (req, res, next) {
  // req.files is array of `photos` files
  // req.body will contain the text fields, if there were any
})

So you actually need to call

upload.single('avatar')(req, {}, function (err) {
  if (err) throw err

  // req.file, req.files...
})
2reactions
LinusUcommented, Nov 15, 2016

You can call the middleware function with just an empty object as res:

upload(req, {}, function (err) {
  if (err) throw err

  // req.file, req.files...
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Upload to S3 using multer without a middleware function
Option 1 - Use multer-s3-transform middleware to handle S3 upload with file transformations, like image resizing using sharp.
Read more >
Upload to S3 using multer without a middleware function
5. 2. I am using multer to upload media to my s3 bucket. I am using multer-s3 as a middleware to upload media...
Read more >
Express multer middleware
Multer is a node. js middleware for handling multipart/form-data , which is primarily used for uploading files. It is written on top of...
Read more >
Multer: Easily upload files with Node.js and Express
Multer is a Node.js middleware for handling multipart/form-data that makes the otherwise painstaking process of uploading files ...
Read more >
Can multer work without the express framework ? : r/node
Well multer creates express middlewares, but you can easily create an adapter around it and use it outside of an express context. All...
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