I am done with all setup of the s3 bucket and using the correct secret keys,
I want to upload a file from my application using nodejs APIs for uploading and get the file URL from the s3 bucket
here is my code:
require("dotenv").config()
const express = require('express')
const app = express();
app.listen(3001,()=>{
console.log("Runnning.......")
});
const aws = require('aws-sdk')
const multer = require('multer')
const multerS3 = require('multer-s3');
aws.config.update({
secretAccessKey: process.env.ACCESS_SECRET,
accessKeyId: process.env.ACCESS_KEY,
region: process.env.REGION,
});
const BUCKET = process.env.BUCKET
const s3 = new aws.S3();
const upload = multer({
storage: multerS3({
s3: s3,
acl: "public-read",
bucket: BUCKET,
key: function (req, file, cb) {
console.log(file);
cb(null, file.originalname)
}
})
})
app.post('/upload', upload.single('file'), async function (req, res, next) {
res.send('Successfully uploaded ' req.file.location ' location!')
})
CodePudding user response:
My problem is solved by downgrading multer-s3 package from version 3 to 2.