WordPress.org

Make WordPress Core

Opened 2 weeks ago

Last modified 10 hours ago

#47987 new defect (bug)

REST API: Add handling of PHP fatal errors while resizing images after upload

Reported by: azaozz Owned by:
Milestone: 5.3 Priority: high
Severity: normal Version:
Component: REST API Keywords: needs-patch
Focuses: Cc:

Description (last modified by azaozz)

Update WP_REST_Attachments_Controller to be able to handle subsequent requests for making missing image sub-sizes similarly to #47872.

Change History (5)

#1 @azaozz
2 weeks ago

Generally when uploading an image the client should be able to send an unique "upload reference" which is then stored in a transient for one hour, and deleted if all image sub-sizes were created successfully. See
https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/media.php?rev=45934#L379 and
https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/media.php?rev=45934#L417.

Then if the response is HTTP 500, the client should be able to do another request including the upload reference from above, and the server should try to make any missing image sub-sizes. The upload reference is used to find the new attachment ID as the client doesn't know it yet. On the server side that would work similarly to:
https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/ajax-actions.php?rev=45934#L2416.

Then, if all attempts fail, the client should be able to do a "cleanup": delete the just created attachment. Again, the upload reference is used to find the attachment ID.

And lastly, the error message shown should be... More helpful than the default "This site is experiencing difficulties...". That could be on the client side though.

This is now implemented in #47872 for the media library screen, Add New media (old upload UI), and the media modal. Any suggestions for improvements welcome :)

Last edited 13 days ago by azaozz (previous) (diff)

This ticket was mentioned in Slack in #core-editor by azaozz. View the logs.


11 days ago

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


7 days ago

#4 @azaozz
14 hours ago

  • Description modified (diff)
  • Keywords needs-patch added

#5 @azaozz
10 hours ago

Added three "helper functions" that deal with the temp upload ref in [46174].

Note: See TracTickets for help on using tickets.