Fix .mov file uploads: handle missing MIME type in browsers like Firefox#601
Open
Jefsky wants to merge 1 commit into
Open
Fix .mov file uploads: handle missing MIME type in browsers like Firefox#601Jefsky wants to merge 1 commit into
Jefsky wants to merge 1 commit into
Conversation
When uploading .mov files in Firefox, the browser reports an empty MIME type, causing FileReader.readAsDataURL to return a data URL with 'application/octet-stream'. The existing fallback in fileToDataURL only corrected the MIME type when file.type was non-empty, so .mov files ended up with the wrong MIME type prefix. This change introduces inferMimeType() which falls back to mapping the file extension when file.type is empty. The same fix is applied to both ImageUpload.tsx and UploadTab.tsx. Fixes abi#384
Author
|
Friendly bump — this PR has been sitting for a bit. The fix detects |
Owner
|
Will take a look soon |
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.
Problem
When uploading a
.movvideo file, the browser (particularly Firefox) sometimes reports an empty MIME type (file.type === ""). This causesFileReader.readAsDataURL()to produce a data URL withdata:application/octet-stream;base64,...instead of the correctdata:video/quicktime;base64,....The existing
fileToDataURL()function had a fallback that only ran whenfile.typewas non-empty, so the MIME type was never corrected for these browsers. The incorrectapplication/octet-streamprefix then caused files to be misclassified downstream.Root Cause
The condition
result.startsWith("data:application/octet-stream") && file.typeskipped the MIME correction whenfile.typewas an empty string (a falsy value in JavaScript).Fix
Added an
inferMimeType()helper that:file.typewhen available (same as before)file.typeis emptyThe extension-to-MIME mapping covers
.mov,.mp4,.webm,.png,.jpg/.jpeg,.gif, and.webp.The fix is applied to both file upload components:
frontend/src/components/ImageUpload.tsxfrontend/src/components/unified-input/tabs/UploadTab.tsxFixes #384