[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
Mon Sep 30 21:01:19 UTC 2024
#54738: Unable to upload images with URL over API when the image doesn’t have a
filetype in the filename
-------------------------------------------------+-------------------------
Reporter: masteradhoc | Owner: joedolson
Type: enhancement | Status: accepted
Priority: normal | Milestone: 6.7
Component: Media | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests needs- | Focuses: rest-api
testing 2nd-opinion |
-------------------------------------------------+-------------------------
Changes (by joedolson):
* keywords: has-patch has-unit-tests needs-testing needs-refresh => has-
patch has-unit-tests needs-testing 2nd-opinion
Comment:
Reproduction is a little tricky for this.
`media_sideload_image()` doesn't work because it has a check for the file
extension before it goes to `download_url`; and `download_url` returns a
string, but `media_handle_sideload` requires a file array.
{{{
$file_array = array();
$file_array['name'] = 'test.jpg';
// Download file to temp location.
$file_array['tmp_name'] = download_url(
'https://img.ricardostatic.ch/t_1800x1350/pl/1187743940/3/1/' );
$handle = media_handle_sideload( $file_array );
}}}
This works; but requires you to manually define the file name.
Given that this is really only a tool for extenders, that may be just
fine, but I'd like a 2nd opinion before moving this forward.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54738#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list