anacronw / multer-s3

multer storage engine for amazon s3
MIT License
660 stars 190 forks source link

Setting Metadata from request body as example not working #128

Closed boypanjaitan16 closed 4 years ago

boypanjaitan16 commented 4 years ago

I tried like the example but nothing working about setting metadata.

const upload = multer({
    storage: multerS3({
        s3          : s3,
        bucket      : 'teduhku',
        contentType : multerS3.AUTO_CONTENT_TYPE,
        metadata    : function (req, file, cb) {
            console.log(req.body);
            cb(null, Object.assign({}, req.body));
        },
        key         : function (req, file, cb) {
            console.log(req.params);

            const exp   = file.originalname.split('.');
            //const fname = req.params.title.replace(/[^0-9a-zA-Z.]/g, '-').toLowerCase();
            const ext   = exp.pop().toLowerCase();
            cb(null, `${Date.now().toString()}.${ext}`);
        }
    })
});

and this is how triggered

app.post('/music/upload', upload.array('files', 3), (req, res) => {
    res.json({
        'status'    : 'success'
    });
});
boypanjaitan16 commented 4 years ago

the error sai that req.params.title is undefined, bu I pretty sure that i set the field from the form

boypanjaitan16 commented 4 years ago

never mind, I got it