-
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
Media Utils: Restrict file uploads with multiple
prop in uploadMedia
and mediaUpload
#69175
Changes from 3 commits
e3181a0
76d06c1
d6f3827
d1c61d1
9b55f51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,8 @@ interface UploadMediaArgs { | |
wpAllowedMimeTypes?: Record< string, string > | null; | ||
// Abort signal. | ||
signal?: AbortSignal; | ||
// Whether to allow multiple files to be uploaded. | ||
multiple?: boolean; | ||
} | ||
|
||
/** | ||
|
@@ -57,6 +59,7 @@ interface UploadMediaArgs { | |
* @param $0.onFileChange Function called each time a file or a temporary representation of the file is available. | ||
* @param $0.wpAllowedMimeTypes List of allowed mime types and file extensions. | ||
* @param $0.signal Abort signal. | ||
* @param $0.multiple Whether to allow multiple files to be uploaded. | ||
*/ | ||
export function uploadMedia( { | ||
wpAllowedMimeTypes, | ||
|
@@ -67,7 +70,18 @@ export function uploadMedia( { | |
onError, | ||
onFileChange, | ||
signal, | ||
multiple = true, | ||
}: UploadMediaArgs ) { | ||
if ( ! multiple && filesList.length > 1 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a unit test for this accordingly in |
||
onError?.( | ||
new UploadError( { | ||
code: 'GENERAL', | ||
message: __( 'Only one file can be used here.' ), | ||
} ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just use a regular |
||
); | ||
return; | ||
} | ||
|
||
const validFiles = []; | ||
|
||
const filesSet: Array< Partial< Attachment > | null > = []; | ||
|
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.
The change here is unnecessary, let's revert that.