Opened 9 years ago
Last modified 15 months ago
#41608 new defect (bug)
Post files using cURL
| Reported by: | codealfa | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | HTTP API | Version: | 4.6 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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
@
9 years ago
- Version 4.8.1 → 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
@
9 years ago
Ok thanks for the info. I've done that at https://github.com/rmccue/Requests/issues/289
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.