loading...
Play Button Pause Button

How to upload files with Node.js

codebubb profile image James Bubb ・2 min read

Originally published here on YouTube.
(Please give me a thumbs up and subscribe if you found this useful 🙏).

Also, part 2 of this tutorial is available here.

Get a copy of the code here: https://github.com/codebubb/tutorial-nodejs-file-upload

Docs for the Node.js multer npm package: https://www.npmjs.com/package/multer

Docs for the Node.js multer-s3 npm package:
https://www.npmjs.com/package/multer-s3

How To Upload Files With Node.js

00:00 Introduction
00:17 Setting up
04:00 Uploading to a private server
04:50 Using multer
06:28 Customising uploaded filename
09:25 Uploading multiple files
15:41 Creating an S3 bucket
16:12 Getting AWS Access Credentials
19:06 Summary

— Follow Me —
Twitter: https://www.twitter.com/codebubb
Facebook: https://www.facebook.com/juniordevelopercentral/
Blog: https://www.juniordevelopercentral.com/
— Thanks! —

So in this Node.js tutorial, we're going to take a look at how to upload files with Node.js.

To start off with we'll install the necessary dependencies (express & multer mainly) to handle the receipt and processing of files uploaded. But before we start setting up our Node.js code, we'll create a simple HTML form that can deliver the files submitted to us via the user in a web browser.

With the form setup, we'll take a simple example of the Node js multer package will is easy to configure if we just want to upload a simple file. Then we'll see how we can use multer with express inside our Node js application to customise how the file is named when it is stored.

To round off our first section, we'll look at how to upload multiple files with Node.js at the same time.

Once we've got a working version that will upload files with Node.js on a private server, we'll move on to working with uploading to the AWS S3 service.

You'll see how you need to use the aws-sdk and multer-s3 packages to configure the processing of your uploads. Once the code is written, i'll show you how to create a new bucket in S3 and also download the necessary credentials to enable the aws-sdk to successfully upload your files to S3.

Discussion

pic
Editor guide