Node.js RestAPIs Download File from Amazon S3 | using Express, AWS-SDK
Tags: node, express, amazon, s3
Published: 2021-05-03 18:11:44

https://grokonez.com/aws/amazon-s3/node-js-restapis-download-file-from-amazon-s3-using-express-aws-sdk


Node.js RestAPIs Download File from Amazon S3 | using Express, AWS-SDK

In the tutorial, we show how to build a Node.js/Express RestAPIs to Download Files from Amazon S3 using AWS-SDK.

Previous post:
- <a href="https://grokonez.com/aws/node-js-restapis-upload-file-to-amazon-s3-using-express-multer-aws-sdk">Node.js RestAPIs upload file to Amazon S3</a>

Related posts:
– <a href="https://grokonez.com/node-js/sequelize/node-js-express-rest-api-postgresql-example-upload-file-download-file-multer-sequelize-crud#Setting_up_NodeJsExpress_project">Node.js/Express – PostgreSQL example – Upload File/Download File – Multer + Sequelize CRUD</a>
– <a href="https://grokonez.com/node-js/nodejs-express-bootstrap-image">NodeJS/Express – Bootstrap Image example</a>
– <a href="https://grokonez.com/node-js/mongoose-many-to-many-related-models-with-nodejs-express-mongodb">Mongoose Many-to-Many related models with NodeJS/Express, MongoDB</a>

Related pages:
<ul>
<li><a href="https://grokonez.com/nodejs-tutorial">Node.js Tutorial</a></li>
</ul>

<!--more-->
<h2>Technologies</h2>
<ul>
<li>Node.js</li>
<li>Express</li>
<li>AWS-SDK</li>
<li>Amazon S3</li>
</ul>
<h2>Overview</h2>
<h3>Demo</h3>

<iframe width="853" height="480" src="https://www.youtube.com/embed/88AdUlRvKLo?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

<h3>Goal</h3>
We create a Node.js project as below ->

<img src="https://grokonez.com/wp-content/uploads/2018/08/nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-project-structure.png" alt="nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-project-structure" width="225" height="303" class="alignnone size-full wp-image-14440" />

Expose a RestAPI: <code>'/api/files/:filename'</code>

File on Amazon S3 ->

<img src="https://grokonez.com/wp-content/uploads/2018/08/nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-file-on-s3-amazon.png" alt="nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-file-on-s3-amazon" width="461" height="376" class="alignnone size-full wp-image-14441" />

Download File ->

<img src="https://grokonez.com/wp-content/uploads/2018/08/nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-get-file-successfully.png" alt="nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-get-file-successfully" width="421" height="389" class="alignnone size-full wp-image-14442" />

Error ->

<img src="https://grokonez.com/wp-content/uploads/2018/08/nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-get-file-wrong-key-fail.png" alt="nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-get-file-wrong-key-fail" width="522" height="185" class="alignnone size-full wp-image-14443" />
<h2>Practice</h2>
<h3>Setting up Node.js project</h3>
Create a folder <strong>NodejsDownloadFileAmazonS3</strong>, then init Node.js project ->

More at:

https://grokonez.com/aws/amazon-s3/node-js-restapis-download-file-from-amazon-s3-using-express-aws-sdk


Node.js RestAPIs Download File from Amazon S3 | using Express, AWS-SDK