I have a private aws s3 container full of images I want to use on my SPA. On the backend I am using express, to try to get access to these images. This is my code on node, where I get the object from s3 container, but I don't know how to display the image from the frontend, is there a way to do this? Do I have to make my s3 container public and use the URL, I was hoping to avoid this. Thanks
let express = require('express')
let router = express.Router();
const aws = require('aws-sdk');
require('dotenv').config();
router.get('/', async (req,res) => {
try{
aws.config.setPromisesDependency(); //use so you can promisify to get the actual images
aws.config.update({
accessKeyId: process.env.ACCESSKEYID,
secretAccessKey: process.env.SECRETACCESSKEY,
region: 'us-east-1'
});
const s3 = new aws.S3();
const list = await s3.listObjectsV2({
Bucket: 'xxx-xxx-xxx'
}).promise()
res.send(list)
} catch(e) {
console.log('our error is',e)
}
})
module.exports = router;
Could it be that I have to change the Content-Type? Since when I get the response from this, it's "application/json; charset=utf-8" when I read it in the chrome developer tool.