InterviewHubPRO
Section Overview
Q44

Question 44 of 60

Part 4: Express, Fastify, APIs & Middleware (36 - 50)

73%
Node.js & Libuv•Part 4: Express, Fastify, APIs & Middleware (36 - 50)

File Uploads in Express: `multer` vs direct streaming.

In Simple Words:

  • multer: Parses multipart/form-data and 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-storage Upload, 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();