Opened 15 months ago
Last modified 4 months ago
#63294 new defect (bug)
Got this error when send image via REST API on WP 6.8
| Reported by: | Astraport | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | REST API | Version: | 6.8 |
| Severity: | critical | Keywords: | reporter-feedback |
| Cc: | Focuses: |
Description
{"code":"rest_upload_image_type_not_supported","message":"The web server cannot generate responsive image sizes for this image. Convert it to JPEG or PNG before uploading.","data":{"status":400}}
Attachments (1)
Change History (11)
#2
in reply to: ↑ 1
@
15 months ago
Replying to mukesh27:
Hi there!
Could you please share image details and rest API call if possible?
Hi
Any image, it doesn't matter. But if I rename the image extension to JPEG instead of JPG and change "Content-Type: image/jpeg" in the request instead of "Content-Type: image/jpg", then everything works and image uploads successfully.
#3
follow-up:
↓ 6
@
15 months ago
- Keywords reporter-feedback added; needs-patch removed
Hi @Astraport if your images have MIME types that are not aligned with the image format or are outside the limits, they will not be accepted. This is normal behaviour and should be expected, you don't want some virus pretended to be an image and such things are happening.
To see what types are allowed, you can check wp_get_mime_types() function.
Please clarify what MIME types and formats you have and where they come from to move forward — how it has happened in the first place, usually people don't have such issues at all. Possibly you need to check with the image source.
This ticket was mentioned in Slack in #core by jorbin. View the logs.
15 months ago
#5
@
15 months ago
Additionally if you visit the Tools -> Site Health menu then switch to the Info tab and open the Media Handling section, you can see which mime types are supported by your server.
@
15 months ago
The same image uploaded through the Media library gets through without problems but uploading that image through Upload function will fail
#6
in reply to: ↑ 3
@
15 months ago
Replying to oglekler:
Hi @Astraport if your images have MIME types that are not aligned with the image format or are outside the limits, they will not be accepted. This is normal behaviour and should be expected, you don't want some virus pretended to be an image and such things are happening.
To see what types are allowed, you can check wp_get_mime_types() function.
Please clarify what MIME types and formats you have and where they come from to move forward — how it has happened in the first place, usually people don't have such issues at all. Possibly you need to check with the image source.
I believe there is more to that. The same image uploaded through the Media library gets through without problems but uploading that image through Upload function will fail with the error mentioned by the OP.
Similarly drag and dropping image into media upload box in Editor will fail with same error.
Attached image above for reference what I'm talking about.
Also this works without issues in older versions i.e. 6.7.1 and 6.7.2. The problem was introduced in 6.8 seems.
#7
@
15 months ago
+1 for this. I use the REST API to upload SVG images to the media library and this 100% broke after upgrading my site to 6.8.
The suggested workaround above works for me and SVG upload works again. Thanks @QuietNoise!
add_filter( 'wp_prevent_unsupported_mime_type_uploads', function( $prevent_upload, $mime_type ) {
if ( 'image/svg+xml' === $mime_type ) {
return false;
}
return $prevent_upload;
}, 10, 2 );
#8
@
15 months ago
+1 for this. Also used @QuietNoise solution since i need SVG upload (via REST-API) for my page builder. It appears that this change was not really thought through.
#9
in reply to: ↑ description
@
13 months ago
Replying to Astraport:
{"code":"rest_upload_image_type_not_supported","message":"The web server cannot generate responsive image sizes for this image. Convert it to JPEG or PNG before uploading.","data":{"status":400}}
I had this exact error in a local installation.
I installed two instances of WP with XAMPP - one using 6.7.1, and the other using 6.8.1.
The image upload issue did not occur in the 6.7 instance, but it did happen in the 6.8
I'd done nothing to either instance outside of installing WP and creating a test page.
This is clearly a WordPress iussue.
#10
@
4 months ago
How does the fact that a PHP installation doesn't support processing of a certain image type relate to the server's inability to upload, i.e. store a file?
If the server is unable to generate various file sizes it shouldn't prevent user from uploading valid files.
Would this lead to users uploading 10Mb images which would show unoptimized? - yes, but it's not up to the core function to enforce such drastic measures. Emit a warning, for goodness' sake!
Moreover, why does the error message is hard-coded?
Convert it to JPEG or PNG before uploading
What if we're uploading JPEG or PNG but the real problem is that imagetypes() doesn't report it as supported?
To enable behavior prior to WP 6.7, it's possible to use wp_prevent_unsupported_mime_type_uploads filter:
<?php add_filter('wp_prevent_unsupported_mime_type_uploads', function ($prevent, $fileType) { return !$fileType || !str_starts_with($fileType, 'image/'); }, 10, 2);
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi there!
Could you please share image details and rest API call if possible?