Open ThatStevensGuy opened 3 years ago
I have the same problem with Wordpress 5.6
I was able to reproduce this with WP 5.7.2 and Gutenberg trunk.
Related: #16297
Related: #18593
I'm still having this problem in 6.0.2 with the additional bug that allowedTypes isn't respected when you select a file from the media gallery either.
I only want to allow selection of images, but even with allowedTypes set to ["image"] I can still select, for example, videos
Hi, @andreaslindahl
Can you share an example code from your plugin?
Core blocks use the same prop/settings, and I cannot reproduce the issue there.
I'm just doing this:
<MediaUpload
onSelect={onSelectMedia}
value={mediaId}
allowedTypes={["image"]}
render={({open}) => (
<Button
variant="secondary"
icon={ mediaId ? 'edit' : 'plus' }
onClick={open}
> { mediaId ? 'Change media' : 'Choose media' }</Button>
)}
/>
I took a look at this during contributor day, dropping a few notes here:
accepts
parameter (or perhaps the allowedTypes
parameter based on the docs?). eg. Dragging a non image over the media component shouldn't highlight the area as a drop target. This change is likely in packages/components/src/drop-zone/index.tsx
in the onDragStart
function. Here are some example screenshots of using Chrome and trying to upload a test HEIC format image to the editor and then to the media library (which prevents the upload entirely). These came up in the context of https://core.trac.wordpress.org/ticket/53645.
Editor upload:
Media library upload (of same file):
@adamsilverstein, related to HEIC issue - #60244.
Describe the bug I am using a duplicate of the Post Featured Image component for a Newsletter attachment which saves to its own post meta.
I noticed that the MediaUpload component will restrict files in the Media Library to the allowed types set in the allowedTypes prop.
However it will still allow any file to be uploaded to the Upload files tab, and then selected.
To fix this I had to add my own mime detection to the onSelect action, which shouldn't really be necessary. Either the Select button should remain disabled after the wrong file type has been uploaded, or the file upload should not be allowed to enter the media library with an error notice.
To reproduce Add MediaUpload to a component, restrict mime types in allowedTypes, then head to the Upload files tab and upload an unsupported file type. It will not appear in the Media library tab, however you can select the file and add it without further mime type detection in your onSelect.
Expected behavior It should not allow the upload of unsupported file types, or not allow selection of the unsupported file.
Editor version (please complete the following information):