The relevant packages I'm using are aws-sdk
, multer-s3
, and multer
.
I have the upload setup as such:
aws.config.update({
secretAccessKey: "accessKey",
accessKeyId: "keyId",
region: "eu-west-2"
});
var s3 = new aws.S3();
const upload = multer({
storage: multerS3({
s3,
acl: "public-read",
bucket: "my-buckets-name",
metadata: function(req, file, cb) {
console.log("passed1"); // prints
cb(null, {
fieldName: "file.fieldname"
});
},
key: function(req, file, cb) {
console.log("passed2"); // prints
cb(null, Date.now().toString());
}
})
});
My route goes something like this,
router.post(
"/single",
[auth, upload.single("image")],
async (req, res) => {
console.log("hereiam"); // never reached
res.json({
msg: "Server received media. Processing..."
});
if (mediaType === "image") {
try { /*...*/ } catch { /*...*/ }
} else { /*...*/ }
Both of the passed1
and passed2
are outputted to the console, and I'm positive that my access key and key ID are correct. When I try to upload an image, I'm thrown a 403 error.
I'm using react native, and I was doing
const aws = require("aws-sdk/dist/aws-sdk-react-native");
That gave me absolutely no feedback at all, the program just continued going as if it nothing happened after I clicked "upload."
Then I changed the nodejs import to,
const aws = require("aws-sdk");
And now I'm being thrown a 403. Not sure what I'm doing wrong.
Edit:
Permissions of my S3: