-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix mp3 uploads on chrome #7398
Conversation
utils/mediaupload.js
Outdated
const [ generalMimeType ] = mime.split( '/' ); | ||
const extensions = extensionsString.split( '|' ); | ||
return [ mime, ...map( extensions, ( extension ) => `${ generalMimeType }/${ extension }` ) ]; | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's possible to unit test that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good and a reasonable change. I'm not entirely sure which upload flow to use for testing this. Uploading mp3 to the media library worked fine for me in Chrome.
Also agree with Riad: This should be a separate, tested function. We should avoid inlining complex logic like this.
utils/mediaupload.js
Outdated
@@ -49,8 +49,19 @@ export function mediaUpload( { | |||
|
|||
// Allowed types for the current WP_User | |||
const allowedMimeTypesForUser = get( window, [ '_wpMediaSettings', 'allowedMimeTypes' ] ); | |||
// Browsers may use unexpected mime types and they defer from browser to browser. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "defer" -> "differ"
utils/mediaupload.js
Outdated
// This solves the problem in chrome where mp3 files have audio/mp3 instead of audio/mpeg. | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=227004 | ||
const flexibleAllowedMimeTypes = flatMap( allowedMimeTypesForUser, ( mime, extensionsString ) => { | ||
const [ generalMimeType ] = mime.split( '/' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Canonical name for this value is its "type" (the part after slash being its "subtype"):
1292f11
to
47df3ec
Compare
47df3ec
to
afca519
Compare
Thank you for the reviews they were addressed, regarding the testing instruction before this PR was merged It was impossible to upload mp3 in the audio block now it should be possible. I'm not aware and I hope there no other noticeable changes. |
* @param {?Object} wpMimeTypesObject Mime type object received from the server. | ||
* Extensions are keys separated by '|' and values are mime types associated with an extension. | ||
* | ||
* @return {?Array} Media Object Promise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return description is inaccurate (copy-pasta from createMediaFromFile
🍝 )
Description
Regressed in: #6968
In #6968 we started validating mime types on the client. It seems mime types used by the browsers may not be the expected ones.
For example, chrome has a bug where mp3 files use audio/mp3 instead of audio/mpeg, so this made uploading mp3 files impossible: https://bugs.chromium.org/p/chromium/issues/detail?id=227004.
In this PR we use extensions to compute possible equivalent mime types making the validation more flexible.
How has this been tested?
Verified uploads still work as before.
Verified it is now possible to upload mp3 files on chrome.