[wp-trac] [WordPress Trac] #54738: Unable to upload images with URL over API when the image doesn’t have a filetype in the filename
WordPress Trac
noreply at wordpress.org
Tue Jan 4 15:37:53 UTC 2022
#54738: Unable to upload images with URL over API when the image doesn’t have a
filetype in the filename
--------------------------+-----------------------------
Reporter: masteradhoc | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version:
Severity: normal | Keywords:
Focuses: rest-api |
--------------------------+-----------------------------
**Problem**: It’s not possible to upload images with URL per API when the
image doesn’t have a filetype in the filename.
**Elaboration**: There are some websites which don’t put filetypes inside
the URL for images. For example:
https://img.ricardostatic.ch/t_1800x1350/pl/1187743940/3/1/
Or: https://media.istockphoto.com/photos/coppersmith-repair-copper-kettle-
on-fire-in-kashgar-in-xinjiang-picture-id1298102169?s=612x612
The format of the image is set and recognized by the browser with the
MIME-Type. In theory WordPress could handle this, but unfortunately it
never gets to the point where the correct MIME type is read out of the
image signature.
**Reason**: At the function wp_check_filetype type will always be defined
as false - if there is no filetype set inside the filename.
Call of the function:
https://github.com/WordPress/WordPress/blob/266c58518846201a7e98cd7995ce2c7429caf1db
/wp-includes/functions.php#L2984
Further down there would be a function to get back the real mime type from
the signature of the image. However, the function is never called since
type at this point is always false in that give case:
https://github.com/WordPress/WordPress/blob/266c58518846201a7e98cd7995ce2c7429caf1db
/wp-includes/functions.php#L2999
**Possible Bug**: If the filename has no filetype the function
wp_get_image_mime should always be called to get the type from the
signature of the image.
**Following Bug**: After changing this, the filename at the upload should
be extended with the filetype:
https://github.com/WordPress/WordPress/blob/266c58518846201a7e98cd7995ce2c7429caf1db
/wp-admin/includes/file.php#L924
Since it’s only really showing up in the library with the correct
filetype.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54738>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list