Open hood opened 4 years ago
Hello, I've just updated this project and submitted a pull request about 10 days ago.
There's no answer by now.
Meanwhile I've added some new features I needed for a project. I'm considering release a new package today or tomorrow. You're welcome to contribute!
The fork is available as multer-cloud-storage and is updated up to Google Cloud Storage's API v5.0.1, released some days ago.
The only drawback is that it supports only node>=10.
Hello @alexandre-steinberg, your fork works great man. Thank you.
But I've some issues when uploading multiple files using .array()
or .any()
. The files successfully uploaded to google cloud storage, but the returning path
and filename
on req.files
object contain the same string for all the files uploaded.
Here's the result when I tried to log the req.files
:
{
fieldname: 'post',
originalname: 'claim-email.png',
filename: '1591658243037-ce-after-event.pdf',
path: 'post/1591658243037-ce-after-event.pdf',
uri: '.../post/1591658243037-ce-after-event.pdf',
linkUrl: '.../post/1591658243037-ce-after-event.pdf'
},
{
fieldname: 'post',
originalname: 'ce-after-event.pdf',
filename: '1591658243037-ce-after-event.pdf',
path: 'post/1591658243037-ce-after-event.pdf',
uri: '.../post/1591658243037-ce-after-event.pdf',
linkUrl: '.../post/1591658243037-ce-after-event.pdf'
}
Any idea how I can fix that?
I'll check it. In meantime, could you send some details as how are calling multer and configuring the storage engine? Are you passing any custom function for nameing or just working with the defaults?
Thank you for the response man.
Yes, I did have a custom function for naming the files. For now, I've got a workaround by using req.file.selfLink
value and process it to get the filename returned by multer.
Here's my config:
import multerGcs from 'multer-cloud-storage'
export const fileHandler = multer({
storage: new multerGcs({
keyFilename: path.join(__dirname, '../../../keyfile.json'),
projectId: 'project-id',
bucket: 'bucketname',
acl: 'publicRead',
destination: 'regulasi/',
filename: (req, file, cb) => cb(null, `${Date.now()}-${file.originalname}`)
})
})
export const handleUpload = (req, res) => {
console.log(req.files)
res.json({files: req.files})
}
And here's how I called the function:
router.post('/file', fileHandler.array('regulasi'), handleUpload)
Facing same issue, any update on this?
Fixed on v2.3.0. All packages were also updated, including Google API to v5.1.1.
Have fun!
Thanks @alexandre-steinberg ! Now its working fine.
@alexandre-steinberg Thank you so much sir!
Is this project still being worked on? If not, I'd like to fork it and create a new package picking where this left off.