Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying private S3 images in node express app

I am developing a node express web application and I am trying to figure out how to display private s3 images when performing a query or single request for an image to views for proper html rendering. I've looked around and didn't find enough information to fully wrap my head around this.

To reiterate, I cannot publicly host them. They have to be privately stored and retrieved when a user uses my express app. I've tried knox which is great for piping, but I don't know how to display all images in one go to a query results page for example. Or more importantly, how to show the raw image data recieved from knox. I also read some stuff about Amazon CloudFront and all that stuff, but would like to exhaust some closer options than doing more and more configuration.

So, how can I view these private s3 images from an express web app? More specifically, displaying a collection of images or a single image.

like image 560
Corey Berigan Avatar asked Dec 03 '25 18:12

Corey Berigan


1 Answers

So if your goal is to have the server fetch the images and then send them to the client, it looks like knox should be able to help you:

from their Github page, with tweaks:

app.get('/img/:filename', function(req, res){
    client.getFile('/whatever/' + req.query.filename, function(err, s3res){
     s3res.pipe(res)
    });
}

Note: untested.

like image 128
Jephron Avatar answered Dec 06 '25 07:12

Jephron