Opened 6 weeks ago
Closed 6 weeks ago
#64836 closed defect (bug) (fixed)
Media: skip server image support check when not generating sub-sizes
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | trunk |
| Component: | Media | Keywords: | has-patch has-unit-tests commit |
| Focuses: | Cc: |
Description (last modified by )
Summary
REST API: Skip server-side image editor support check when generate_sub_sizes is false
Description
When uploading images via the REST API with generate_sub_sizes set to false, the server still checks whether the image editor supports the uploaded image format. This causes uploads of formats like AVIF to fail with rest_upload_image_type_not_supported, even though the client is handling all image processing and the server doesn't need to generate any sub-sizes.
The generate_sub_sizes parameter was introduced to allow clients (such as the block editor with client-side media processing) to handle image resizing themselves. When this parameter is false, the server-side image editor support check is unnecessary and should be skipped.
Steps to Reproduce
- Enable client-side media processing in the block editor (or use the REST API directly with
generate_sub_sizes=false) - Attempt to upload an AVIF image on a server where the image editor does not support AVIF
- The upload fails with
rest_upload_image_type_not_supported
Expected Result
The upload should succeed because the client is handling all image processing.
Actual Result
The upload fails with a 400 error: "The web server cannot generate responsive image sizes for this image."
Proposed Fix
In WP_REST_Attachments_Controller::create_item_permissions_check(), after the wp_prevent_unsupported_mime_type_uploads filter is applied, check if generate_sub_sizes is explicitly set to false. If so, set $prevent_unsupported_uploads to false to bypass the server-side image editor support check.
Change History (7)
This ticket was mentioned in PR #11218 on WordPress/wordpress-develop by @adamsilverstein.
6 weeks ago
#2
- Keywords has-unit-tests added
@adamsilverstein commented on PR #11218:
6 weeks ago
#3
## Proposed SVN Commit Message
Media: Skip server image support check when not generating sub-sizes. When uploading images via the REST API with `generate_sub_sizes` set to `false`, the server still checks whether the image editor supports the uploaded image format. This causes uploads of formats like AVIF to fail with `rest_upload_image_type_not_supported`, even though the client is handling all image processing and the server doesn't need to generate any sub-sizes. Skip the server-side image editor support check in `WP_REST_Attachments_Controller::create_item_permissions_check()` when `generate_sub_sizes` is explicitly `false`. See also https://github.com/WordPress/gutenberg/issues/76369 and https://github.com/WordPress/gutenberg/pull/76371. Props adamsilverstein, westonruter, andrewserong. Fixes #64836. See #62717.
@adamsilverstein commented on PR #11218:
6 weeks ago
#4
## Proposed SVN Commit Message
Media: Skip server image support check when not generating sub-sizes. When uploading images via the REST API with `generate_sub_sizes` set to `false`, the server still checks whether the image editor supports the uploaded image format. This causes uploads of formats like AVIF to fail with `rest_upload_image_type_not_supported`, even though the client is handling all image processing and the server doesn't need to generate any sub-sizes. Skip the server-side image editor support check in `WP_REST_Attachments_Controller::create_item_permissions_check()` when `generate_sub_sizes` is explicitly `false`. See also https://github.com/WordPress/gutenberg/issues/76369 and https://github.com/WordPress/gutenberg/pull/76371. Props adamsilverstein, westonruter, andrewserong. Fixes #64836. See #62717.
@mukesh27 commented on PR #11218:
6 weeks ago
#6
Mark ready for commit
## Summary
When uploading images via the REST API with
generate_sub_sizesset tofalse, the server still checks whether the image editor supports the uploaded image format. This causes uploads of formats like AVIF to fail withrest_upload_image_type_not_supported, even though the client is handling all image processing and the server doesn't need to generate any sub-sizes.This PR adds a check in
WP_REST_Attachments_Controller::create_item_permissions_check()to skip the server-side image editor support check whengenerate_sub_sizesis explicitlyfalse.Trac ticket: https://core.trac.wordpress.org/ticket/64836
## Changes
class-wp-rest-attachments-controller.php: After thewp_prevent_unsupported_mime_type_uploadsfilter is applied, check ifgenerate_sub_sizesisfalseand bypass the image editor support check if so.rest-attachments-controller.php(tests): Two new tests:test_upload_unsupported_image_type_skipped_when_not_generating_sub_sizes— verifies upload succeeds withgenerate_sub_sizes=falsetest_upload_unsupported_image_type_enforced_when_generating_sub_sizes— verifies upload still fails withgenerate_sub_sizes=true## Related
## Test Plan
vendor/bin/phpunit tests/phpunit/tests/rest-api/rest-attachments-controller.php --filter="test_upload_unsupported_image_type"