DEV Community

0 seconds of 19 minutes, 45 secondsVolume 90%
Press shift question mark to access a list of keyboard shortcuts
00:00
00:00
19:45
 
James Bubb
James Bubb

Posted on

2 1

How to upload files with Node.js

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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
sherwinwater profile image
Shuwen

Thank you!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay