Menu

File uploads in Express and NestJS with safe defaults, and one interface for disk, S3 and Azure
📰

File uploads in Express and NestJS with safe defaults, and one interface for disk, S3 and Azure

DEV Community: typescript·Elmer Alluad Jr.·about 13 hours ago
#UKWJNO5i
#devtotypescript#devto#dev#storage#multipart
Reading 0:00
15s threshold

Every Node.js backend eventually needs a file upload endpoint. And every time, the same questions come back:

How do I stop someone from uploading a 5 GB file, or 10,000 tiny ones?

How do I make sure ../../etc/passwd never ends up as a filename on my disk?

Why does moving from local disk to S3 (or Azure) mean rewriting my routes?

Why does my "simple upload" pull in a tree of transitive dependencies?

I built @xkid1/multipart to answer those once. It's a multipart/form-data parser written in TypeScript with zero runtime dependencies , Express and NestJS middleware, and storage adapters for the local filesystem, AWS S3 and Azure Blob Storage, all behind one interface.

This post walks through how it works and how to use it.

Install

npm install @xkid1/multipart

Enter fullscreen mode

Exit fullscreen mode

You only install the SDKs for the pieces you use:

You use Also install

Core parser / local nothing

Express express

NestJS @nestjs/common reflect-metadata rxjs

AWS S3 @aws-sdk/client-s3

Azure Blob…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.