fix: correct MIME type detection for file uploads#348
Open
sahilleth wants to merge 1 commit intorazorpay:masterfrom
Open
fix: correct MIME type detection for file uploads#348sahilleth wants to merge 1 commit intorazorpay:masterfrom
sahilleth wants to merge 1 commit intorazorpay:masterfrom
Conversation
Author
|
This change only updates MIME detection logic and includes unit tests. No integration or manual testing is required. |
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
44cd44c to
7b98575
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.