Skip to content

fix: correct MIME type detection and skip duplicate file part in multipart upload - #368

Open
nandanau wants to merge 1 commit into
razorpay:masterfrom
nandanau:fix/multipart-mime-type-and-duplicate-file-part
Open

nandanau wants to merge 1 commit into
razorpay:masterfrom
nandanau:fix/multipart-mime-type-and-duplicate-file-part

Conversation

@nandanau

Copy link
Copy Markdown

Summary

  • Wrong string comparison: getMediaType used == to compare strings (compares references, not values — always false at runtime), so the image branch was never taken
  • Wrong MIME types: Images were returning image/jpg (invalid) instead of image/jpeg, and PDFs were returning image/pdf instead of application/pdf
  • Duplicate file field: fileRequestBody added the file both as a proper multipart file part and again as a plain string form-data part because the iterator loop didn't skip the "file" key

Changes

  • Use .equals() for string comparison in getMediaType
  • Add .toLowerCase() so extension matching is case-insensitive
  • Fix MIME types: image/jpeg for images, application/pdf for PDFs
  • Skip the "file" key in the form-data loop to prevent adding it twice

Test plan

  • Upload a .jpg/.jpeg/.png/.jfif file — verify Content-Type is image/jpeg
  • Upload a .pdf file — verify Content-Type is application/pdf
  • Inspect the multipart request body — verify the file field appears exactly once (as a file part, not also as a string part)

…ipart upload

- Use .equals() instead of == for string comparison in getMediaType (== compares references, always false for string literals at runtime)
- Fix MIME types: image/jpeg for images, application/pdf for PDFs (was image/jpg and image/pdf)
- Add .toLowerCase() so extension matching is case-insensitive
- Skip the "file" key in the form-data loop to prevent adding it twice (once as a proper file part, once as a plain string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant