Node.js & Libuv•Part 4: Express, Fastify, APIs & Middleware (36 - 50)
File Uploads in Express: `multer` vs direct streaming.
In Simple Words:
multer: Parsesmultipart/form-dataand buffers files to disk or RAM.- Direct S3 Streaming (
busboy): Streams chunks directly from the incoming HTTP stream into AWS S3 via@aws-sdk/lib-storageUpload, eliminating local disk space requirements.
javascript
const { Upload } = require('@aws-sdk/lib-storage');
const { S3Client } = require('@aws-sdk/client-s3');
// Directly stream file from incoming HTTP stream to S3:
const upload = new Upload({
client: new S3Client(),
params: { Bucket: 'my-bucket', Key: 'upload.pdf', Body: req }
});
await upload.done();