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

node-js-restapis-download-file-from-amazon-s3-using-express-aws-sdk-feature-image-new

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

Previous post:
Node.js RestAPIs upload file to Amazon S3

Related posts:
Node.js/Express – PostgreSQL example – Upload File/Download File – Multer + Sequelize CRUD
NodeJS/Express – Bootstrap Image example
Mongoose Many-to-Many related models with NodeJS/Express, MongoDB

Related pages:

Technologies

  • Node.js
  • Express
  • AWS-SDK
  • Amazon S3

Overview

Demo

Goal

We create a Node.js project as below ->

nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-project-structure

Expose a RestAPI: '/api/files/:filename'

File on Amazon S3 ->

nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-file-on-s3-amazon

Download File ->

nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-get-file-successfully

Error ->

nodejs-express-restapis-download-file-from-amazon-s3-using-aws-sdk-get-file-wrong-key-fail

Practice

Setting up Node.js project

Create a folder NodejsDownloadFileAmazonS3, then init Node.js project ->

Install Express, AWS-SDK ->

npm install express aws-sdk --save

-> package.json file:

AWS S3 Config

– Create a file ./app/config/s3.env.js ->

– Configure S3 Client in a file ./app/config/s3.config.js ->

Express Router

– Create router in file ./app/routers/s3.router.js ->

Download Controller

– Implement S3 Downloader in a controller file ./app/controllers/s3.controller.js ->

Server.js

server.js file ->

SourceCode

Use npm install to install all dependencies before run the Node.js server with cmd npm start.

NodejsDownloadFileAmazonS3

By grokonez | August 26, 2018.



Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*