I am trying to integrate S3 file storage into my NodeJS application. This tutorial explaining how to upload directly to S3 is very good, but it\'s not suitable for my n
You can use S3 REST API. It will allows you to make signed request to GET or PUT your bucket's objects directly from your backend.
The principle is similar from the one described in your link. Your backend need to use the AWS JS SDK to create a signed URL to manipulate an object. You are free to do any check you want prior or after requesting something from S3 in your Express routes.
Here is a simple GET example (it is not fully functional, just the main idea):
...
[assume that you are in an express route with req/res objects]
...
var aws = require('aws-sdk'),
s3 = new aws.S3();
aws.config.region = 'your_region';
aws.config.credentials = {
accessKeyId: 'your_key',
secretAccessKey: 'your_secret'
};
s3.getSignedUrl('getObject', {Bucket: 'your_bucket', Key: 'your_file_name', Expires: 3600}, function (error, url) {
if (error || !url) {
//error while creating the URL
res.status(500).end();
} else {
//make a request to the signed URL to get the file and pipe the res to the client
request({
url: url
}).pipe(res);
}
});
You will here find more examples from Amazon.