WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 3 months ago

#41608 new defect (bug)

Post files using cURL

Reported by: codealfa Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.6
Component: HTTP API Keywords:
Focuses: Cc:

Description

It's impossible to post files by http using cURL via the WordPress API.

If you look at the code in the setup_handle method in Requests_Transport_cURL class found in the /wp-includes/Requests/Transport/cURL.php file, you'll see that the POST data is always converted to a string using the PHP http_build_query function. However, according to the PHP manual at http://www.php.net/manual/en/function.curl-setopt.php, the value passed to CURLOPT_POSTFIELDS must be an array if files are passed to this option.

Change History (4)

#1 @SergeyBiryukov
3 months ago

  • Component changed from General to HTTP API

#2 @codealfa
3 months ago

A possible fix could be to simply add the post value to the CURLOPT_POSTFIELDS option without converting it to a string if the value is an array and the Content-Type header has been given as multipart/form-data. According to the PHP manual, this Content-Type header will be set if the post value is an array.

#3 @ocean90
3 months ago

  • Version changed from 4.8.1 to 4.6

Hello @codealfa, welcome to WordPress Trac!

Thanks for your report. Please note that Requests is an external library, so this issue should also be reported on the GitHub repo at https://github.com/rmccue/Requests/issues.

Related:

#4 @codealfa
3 months ago

Ok thanks for the info. I've done that at https://github.com/rmccue/Requests/issues/289

Note: See TracTickets for help on using tickets.