You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
varexpress=require('express')varmulter=require('multer')varupload=multer({dest: 'uploads/'})varapp=express()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})varcpUpload=upload.fields([{name: 'avatar',maxCount: 1},{name: 'gallery',maxCount: 8}])app.post('/cool-profile',cpUpload,function(req,res,next){// req.files is an object (String -> Array) where fieldname is the key, and the value is array of files//// e.g.// req.files['avatar'][0] -> File// req.files['gallery'] -> Array//// req.body will contain the text fields, if there were any})
Also, I tried to remove the parameter inMemory (it's the same to set inMemory:false) and had an issue changing the profile image, because our controller uses the buffer (req.files.file.buffer) to change the profile picture.
So, my suggestion is to update the way we use multer, and maybe, remove the parameter inMemory:true and adjust the controller to don't use req.files.file.buffer
The text was updated successfully, but these errors were encountered:
Hi guys,
The multer library has changed, and also they've changed the way of using multer as a middleware in express.
Old way:
New way:
As you can see below, we are using the old way of usage in the config/lib/express.js#L92-L97
At the same time, we are using the parameter inMemory:true, that can lead our apps to run out of memory as pointed out here https://github.com/expressjs/multer#memorystorage
Also, I tried to remove the parameter inMemory (it's the same to set inMemory:false) and had an issue changing the profile image, because our controller uses the buffer (req.files.file.buffer) to change the profile picture.
So, my suggestion is to update the way we use multer, and maybe, remove the parameter inMemory:true and adjust the controller to don't use req.files.file.buffer
The text was updated successfully, but these errors were encountered: