Make WordPress Core

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: adamsilverstein's profile adamsilverstein Owned by: adamsilverstein's profile adamsilverstein
Milestone: 7.0 Priority: normal
Severity: normal Version: trunk
Component: Media Keywords: has-patch has-unit-tests commit
Focuses: Cc:

Description (last modified by adamsilverstein)

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

  1. Enable client-side media processing in the block editor (or use the REST API directly with generate_sub_sizes=false)
  2. Attempt to upload an AVIF image on a server where the image editor does not support AVIF
  3. 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)

#1 @adamsilverstein
6 weeks ago

  • Description modified (diff)

This ticket was mentioned in PR #11218 on WordPress/wordpress-develop by @adamsilverstein.


6 weeks ago
#2

  • Keywords has-unit-tests added

## Summary

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.

This PR adds a check in WP_REST_Attachments_Controller::create_item_permissions_check() to skip the server-side image editor support check when generate_sub_sizes is explicitly false.

Trac ticket: https://core.trac.wordpress.org/ticket/64836

## Changes

  • class-wp-rest-attachments-controller.php: After the wp_prevent_unsupported_mime_type_uploads filter is applied, check if generate_sub_sizes is false and 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 with generate_sub_sizes=false
    • test_upload_unsupported_image_type_enforced_when_generating_sub_sizes — verifies upload still fails with generate_sub_sizes=true

## Related

## Test Plan

  • [ ] Run PHP tests: vendor/bin/phpunit tests/phpunit/tests/rest-api/rest-attachments-controller.php --filter="test_upload_unsupported_image_type"
  • [ ] Verify the two new tests pass and existing tests still pass

@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.

#5 @mukesh27
6 weeks ago

  • Keywords commit added

@mukesh27 commented on PR #11218:


6 weeks ago
#6

Mark ready for commit

#7 @adamsilverstein
6 weeks ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 61980:

Media: skip server image support check when using client-side media.

When uploading images via the REST API with generate_sub_sizes set to false, skip server support checks since processing is handled on the client side. Fix an issue where uploads of formats like AVIF fail with rest_upload_image_type_not_supported, even though the client will handle all image processing and the server doesn't need to support the format.

See also https://github.com/WordPress/gutenberg/issues/76369 and https://github.com/WordPress/gutenberg/pull/76371.

Props adamsilverstein, westonruter, andrewserong, mukesh27.
Fixes #64836. See #62717.

Note: See TracTickets for help on using tickets.