Skip to content

fix: correct MIME type detection for file uploads#348

Open
sahilleth wants to merge 1 commit intorazorpay:masterfrom
sahilleth:fix-getmediatype-mime-detection
Open

fix: correct MIME type detection for file uploads#348
sahilleth wants to merge 1 commit intorazorpay:masterfrom
sahilleth:fix-getmediatype-mime-detection

Conversation

@sahilleth
Copy link

Summary
Fixes incorrect MIME type detection in ApiUtils.getMediaType() used for document uploads (account documents, stakeholder documents, dispute evidence).

Problem
getMediaType() was using reference equality (==) instead of value comparison for string matching of file extensions.
Because of this, extension checks failed and uploads defaulted to an incorrect MIME type (image/pdf), regardless of actual file type. This could lead to:
Incorrect Content-Type headers
Improper validation of non-PDF files
Unexpected API behavior for JPEG/PNG uploads

Solution
Replace reference equality (==) with .equals() for extension comparison
Fix variable typo: extenionName → extensionName
Correct MIME type mappings:
jpg, jpeg, jfif → image/jpeg
png → image/png
pdf → application/pdf

Add safe fallback to application/octet-stream for:
Unknown extensions
Missing extensions
Files with trailing dots

Testing
Added new unit test class: ApiUtilsTest
Covered:
All supported extensions
Case variations (JPG, Pdf, etc.)
Files without extension
Files with trailing dot
Unknown extensions

No changes to public API.
Behavior remains backward compatible except for corrected and standards-compliant MIME types.

@sahilleth
Copy link
Author

This change only updates MIME detection logic and includes unit tests.

No integration or manual testing is required.
Kindly mark this as TestingNotRequired.

getMediaType() used reference equality (==) for string comparison,
which always failed in Java. All uploaded files were incorrectly
sent as "image/pdf" regardless of extension.

- Replace == with .equals() for extension checks
- Fix typo: extenionName -> extensionName
- Return correct MIME types: image/jpeg, image/png, application/pdf
- Handle missing/trailing extension via application/octet-stream
- Add unit tests for getMediaType
@sahilleth sahilleth force-pushed the fix-getmediatype-mime-detection branch from 44cd44c to 7b98575 Compare February 28, 2026 18:10
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