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!
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...
})
That does not work for me. What is the upload function for you? I have this: const upload = multer({ storage });, and the terminal throws an error saying "TypeError: upload is not a function".
On which line does "TypeError: upload is not a function" happen? Can you post your code?
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...
})
Closing as resolved 馃憤
Most helpful comment
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:
So you actually need to call