GithubHelp home page GithubHelp logo

express-multer-aws-s3's Introduction

General Assembly Logo

File upload with express and AWS S3

Prerequisites

Objectives

By the end of this, developers should be able to:

  • Upload files to AWS S3 from a node application.
  • Create path names with a low chance of duplication
  • Store information about uploaded files in MongoDB via Mongoose
  • Upload files from a browser to express and store them in AWS S3.

Preparation

  1. Fork and clone this repository.
  2. Create a new branch, training, for your work.
  3. Install dependencies with npm install.
  4. Install express-api-template into your training directory. In step 2 rename express-api-template to express-multer-api.

Introduction

Adding a feature to a web API can feel formidable.

We'll take a stepped approach to implementing an image upload feature.

Hard problems are hard. We'll work to find and solve an easier problem first.

Discussion

What are the parts of file upload? What are the issues to guard against?

Node packages checklist

We'll use the following node modules as we build out this feature:

  • aws-sdk
  • crypto
  • dotenv
  • mime
  • fs
  • mongoose
  • express
  • body-parser
  • multer

The node package file-type night be more appropriate for getting a content type, but mime is sufficient for the command line portion of our feature build. When we start handling uploads through multer, we'll see that we get file information from it.

Structure

We'll investigate, code, refactor, and integrate all the parts of file upload.

Uploading files to AWS from node

We'll build a command line script in express-multer-api to upload a file to AWS.

Why build a command line uploader?

We'll use AWS.S3, specifically the upload method, to send files to AWS S3.

We'll run the script using npm run upload-aws <file> [comment].

Refactoring is a skill to cultivate.

Let's separate out the parts that aren't about a command line script so we can reuse them.

Uploading files to an echo server from an html form

We'll use the index.html to start file uploads.

We'll use the form attribute enctype="multipart/form-data" to allow uploading of one or more files.

We'll use FormData and $.ajax to POST data to an echo server, http://httpbin.org.

Later we'll use this client to POST data to express-multer-api.

Uploading files to AWS via multer and express

Completing the parts of file upload.

  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

express-multer-aws-s3's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.