Sitemap
Better Programming

Advice for programmers.

How to Upload Media and Process Multipart Forms on Node.js Server

Upload images and other files efficiently

5 min readFeb 3, 2021

--

Press enter or click to view image in full size
Let’s upload ! Photo by vnwayne fan on Unsplash

So you have a frontend app communicating with a backend, and you need to upload media to a CDN provider before handling the metadata? Excellent, we’ll see how you can do that with reuse and flexibility in mind under Node.js.

We’ll cover how to write your server-side CDN service abstracting a CDN provider API, as well as your multipart form data parsing service. And we’ll also briefly handle the client-side code as well.

This is the second installment of my “Solving Real-Life Problems in JavaScript” series. The first installment is about WebSockets.

The Context

We’ll use a CDN provider API. I choose Cloudinary, which is a great tool with many features, a generous free-tier, as well as an npm package for Node.js. For parsing HTML form data, we’ll rely on the excellent busboy library for low-level work.

Now, our goal is to write reusable services abstracting those tools (so that if you need to switch to another CDN provider API, you just have to edit the CDN service for instance) that we can use server-side with our server of choice.

Setting up the CDN Service

--

--

No responses yet