Opened 7 years ago
Last modified 7 years 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)
#3
@
7 years 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
@
7 years ago
Ok thanks for the info. I've done that at https://github.com/rmccue/Requests/issues/289
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.