'upload multiple different files form to amazon s3 bucket using node/ react
please kindly help me out, i am trying to upload multiple different files to s3 bucket as shown in the image below.
and below is what i have tried. the productIMAGE is the filename from the react, likewise the productVIDEO
var file = [
{ name: "productIMAGE", maxCount: 10 },
{ name: "productVIDEO", maxCount: 10 },
{ name: "businessIMAGE", maxCount: 10 },
{ name: "businessVIDEO", maxCount: 10 },
{ name: "certificateIMAGE", maxCount: 10 },
];
var s3 = new AWS.S3({
accessKeyId: process.env.KEY_ID,
secretAccessKey: process.env.SECRET,
Bucket: process.env.BUCKET,
});
var upload = multer({
storage: multerS3({
s3: s3,
bucket: process.env.BUCKET,
metadata: function (req, file, cb) {
cb(null, { fieldName: file.fieldname });
},
key: function (req, file, cb) {
cb(null, Date.now().toString());
},
}),
});
// become a seller ======================================
router.post("/seller", upload.array(file), async (req, res, next) => {
try {
const newSeller = await new SellerAcct({
city: req.body.city,
productIMAGE: req.file.productIMAGE,
productVIDEO: req.file.productVIDEO,
businessIMAGE: req.file.businessIMAGE,
businessVIDEO: req.file.businessVIDEO,
certificateIMAGE: req.file.certificateIMAGE,
});
const seller = await newSeller.save();
res.json({
success: true,
message: "Seller Account Created Successful.",
seller: {
sellerName: seller.sellerName,
},
});
} catch (error) {
res.status(500).json(error + "error saving data");
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

