Skip to content

fix(upload): parse multipart form fields before loadUploadSessionForChunk to fix req.body undefined#212

Open
Git-Shubham14 wants to merge 1 commit into
imanchalsingh:mainfrom
Git-Shubham14:fix/chunk-upload-req-body-undefined
Open

fix(upload): parse multipart form fields before loadUploadSessionForChunk to fix req.body undefined#212
Git-Shubham14 wants to merge 1 commit into
imanchalsingh:mainfrom
Git-Shubham14:fix/chunk-upload-req-body-undefined

Conversation

@Git-Shubham14

Copy link
Copy Markdown

Description

Fixes #203

The chunk upload route was failing with a 500 error because req.body was undefined when loadUploadSessionForChunk tried to destructure sessionId and chunkIndex from it.

Root Cause:
The client sends chunk data as multipart/form-data (FormData). Multer only parses req.body when it runs — but loadUploadSessionForChunk was executing before multer, so req.body was always empty at that point.

Fix:
Added a fieldParser using multer().none() as the first middleware in chunkUploadMiddleware. This parses the multipart form fields (sessionId, chunkIndex) into req.body before loadUploadSessionForChunk runs, without consuming the file chunk itself.

Type of Change

  • Bug fix

Checklist

  • Code follows project style
  • Tested locally (blocked by additional pre-existing server bugs — duplicate passwordAttemptLimiter in rateLimiter.js and missing rate-limit-redis package preventing server from starting)
  • Updated documentation

Pre-existing Issues Found (not caused by this PR)

  • rateLimiter.js — duplicate passwordAttemptLimiter declaration (can be raised as separate issue)
  • rate-limit-redis package missing from dependencies (Redis not configured locally)
  • validateEnv.js — duplicate export default (already fixed in this branch)

@netlify

netlify Bot commented Jul 4, 2026

Copy link
Copy Markdown

👷 Deploy request for file-sharingsystem pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit a994783

@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

@Git-Shubham14 is attempting to deploy a commit to the imanchalsingh Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added SSoC26 Official label of org bug Something isn't working backend labels Jul 4, 2026
@Git-Shubham14

Copy link
Copy Markdown
Author

Hii @imanchalsingh, please check the pr and let me know is it successfully works or not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working SSoC26 Official label of org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: File upload fails with 500 error — req.body is undefined in uploadController

1 participant