Helpful error on upload of image type not supported by server#68644
Helpful error on upload of image type not supported by server#68644adamsilverstein wants to merge 24 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Do you think we should return this error on the REST API level? The Plus, it removes the need to introduce another config argument for media upload utils. |
Good idea, I can try that. |
@Mamaduka I tried this approach and notice an issue I did not anticipate. When the image is dropped on the canvas, we create a faded version of it to display during the upload. Because the error isn't known until the REST API response, that "ghost" image shows until the error is returned: upload.demo.mp4Implementation in a separate branch since I'm not sure we should use it: #68788 |
|
Instead of adding this new field, can't we just omit the non-supported types from |
We could, but the experience would be sub-par, see my comment here: https://core.trac.wordpress.org/ticket/61167#comment:20 after trying that exact approach in this PR: WordPress/wordpress-develop#7629. Basically the error message is cryptic ("Sorry, you are not allowed to upload this file type"), and doesn't help the user figure out what went wrong. The approach in this PR matches the experience in core->Media - the user is informed that the media type they are trying to upload isn't supported by the server and to try converting to a compatible format like JPEG before uploading. |
packages/block-editor/src/components/provider/use-media-upload-settings.js
Outdated
Show resolved
Hide resolved
|
Thanks for pointing to that, very helpful! Showing a different messages for files that could technically be uploaded but just not resized makes sense to me. I'm just wondering whether there is a better way to do that. Right now this touches a lot of files and I'm wary of such a change to the |
|
@swissspidy - this is ready for an additional review whenever you have a chance! |
Can you share reproduction steps from add_filter( 'wp_handle_upload_prefilter', function( $file ) {
$file['error'] = 'File upload error.';
return $file;
} ); |
|
^ I'd also like testing instructions specifically for that. I tried uploading a JXL image in Playground and I see the placeholder for a split second before the error appears and the image is removed.
How about Apart from that, functionality-wise the PR looks good to me. |
@Mamaduka try uploading an AVIF file on a system that doesn't support AVIF.
Sure, great suggestion! |
Updated in 1fd268b |
|
@Mamaduka do you want to give this one more test before I merge? |
|
I'll do another round of tests tomorrow, but it generally looks good. My only concern is yet another block editor setting. This is an old practice that the project tries to avoid nowadays.
I know you also started working on #68788. Why did you choose this solution instead of the REST API alternative? Is it only due to the uploading state issue mentioned above? The current solution seems to have a similar problem.
It would make backport tracking easier. We could use it if you're already working on core PR. See: https://github.com/WordPress/gutenberg/blob/trunk/backport-changelog/readme.md |
I had the same thought but since |
|
Since the upload is "rejected" by the server as unsupported, would it not make more sense to let the REST API handle the error? |
That was previously answered here:
But now that I re-read it again... This behavior was also mentioned with the current patch, though I can't reproduce it there. So can we reopen #68788 again to try this? If the error handling is purely done in |
Exactly. The feedback would be identical to any other server upload error. Below is the emulated error on Slow 4G via ScreencastCleanShot.2025-02-05.at.18.16.31.mp4 |
I can retest #68788, The issue there was the flash of the image showing while the upload started, then failed. In the new approach, the supported types are already known, so the UI can respond immediately, without waiting for the REST request to return an error. I will capture screen captures of both approaches so we can compare the results. I also see some value in knowing which types aren't supported by the server before trying to upload, this could be especially useful to know when leveraging client side image processings. |
|
@adamsilverstein, the screencast I shared on the trunk with an emulated server error. The flash is due to optimistic UI, so I don't think it's breaking anything. The editor starts uploading > displays the blob as a preview while uploading> the server returns an error > the editor displays a notice and returns to an optimistic state. |
I thought about that too at first, but I am actually not sure about that. If we process and convert all the images on the client, including any sub-sizes, then it doesn't really matter if the server can't do it. So we don't have to be constrained by server limitations anymore. |
I was thinking about the case where the client is underpowered, say a mobile device. In that case, you might want to defer to the server if you know it supports the format(s) required. |
|
Fair point. I think in that case that's best explored separately as part of that effort, as right now such information is provided via the REST API and not block editor settings. |
|
I used playground to compare #68644 and #68788. Even without network throttling, the "flash" of the image is clearly visible with 68788, however 68644 has the issue of showing the placeholder with a spinner after a failed upload (when dragging the image on to the canvas). I'm currently favoring #68788 - it is
Here are the screencasts I recorded. I also tested uploading multiple images at once of various types. 6864468644.drag.no.flash.placeholder.mp4pr.68644.-.upload.no.flash.mp46878868788.-.drag.image.-.flash.mp4pr-68788-upload-flashes.mp4WDYT? |
|
Amazing, super helpful comparison! #68788 looks good to me as well. However, can't we just merge that PHP change in WordPress core? I don't see a point in adding this via the plugin. Of course the JS change needs to be done here, but that is a separate enhancement that makes a lot of sense regardless. |
I think that makes sense. |
Good point, I'll move this part back to https://core.trac.wordpress.org/ticket/61167 |
Core PR adding the error message: WordPress/wordpress-develop#8322 GB PR updated to only update error handling: #68788 (comment) |
|
Closing in favor of #68788 |

What?
Reject upload of image types not supported by server - match the behavior when trying to upload the same file types in the media library.
This will fix this issue reported in Trac: https://core.trac.wordpress.org/ticket/61167
Why?
Currently users can upload AVIF, WebP or HEIC images even if their web server doesn't support - meaning WordPress will be unable to process the uploaded image into the sub-sized images used for display on the front end. This matches what we do in the media library - we help users by suggesting they convert their images before uploading them
While the upload might look like it is working currently, since the sub-sized images are not created, the front experience is sub-par and the user might never realize this.
How?
Testing Instructions
Screenshots or screencast
Media library error:

Post editor error:

Missing srcset
