#24156 closed defect (bug) (wontfix)
If you submit file through wp curl it doesnt send boundary params for file mutlipart
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | major | Version: | 3.5.1 |
Component: | HTTP API | Keywords: | has-patch |
Focuses: | Cc: |
Description (last modified by )
If you submit file through wp curl it doesnt send boundary params for file multipart, because in class-http.php at line 174 $r['body']
array is converted to string:
$r['body'] = http_build_query( $r['body'], null, '&' );
And curl wants array to send file boundary to rest api , in that case it fails.
ex.
$headers['Content-type'] = 'multipart/form-data'; $args['file'] = '@/pathtofile'; $request = new WP_Http; $result = $request->request($url,$args);
Let me know if you have questions
Attachments (1)
Change History (8)
#3
@
12 years ago
- Cc samnani added
Hi I have rewritten few line of code and it worked, here i am adding diff file, where i can ask for the review or submit a patch for wordpress code?
#6
@
12 years ago
- Keywords 2nd-opinion removed
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
WP_HTTP is designed to be a abstraction layer which allows you to use any available method of connecting to a remote site.
If you want to use curl functionality, you need to use curl directly.
If someone requires it, please open a new ticket to add generic File uploading capability to WP_HTTP instead.
#7
@
12 years ago
I'm doing it like this and it seems to work fine:
$body = file_get_contents( $filepath ); $mime_type = ''; if ( extension_loaded( 'fileinfo' ) ) { $finfo = new finfo; $mime_type = $finfo->file( $filepath, FILEINFO_MIME ); } elseif ( function_exists('mime_content_type') ) { $mime_type = mime_content_type( $filepath ); } $args = array( 'method' => 'PUT', 'headers' => array( 'Content-Type' => $mime_type, 'X-HTTP-Method-Override' => 'PUT' ), 'timeout' => 30, 'body' => $body, ); $response = wp_remote_request( $url, $args );
To put it bluntly, if you want to use cURL functionalities that WP_HTTP doesn't support, you should probably be using cURL directly.
The other WP_HTTP transports do not support the cURL send-file functionality, and you can't be sure that WP_HTTP will be using cURL on all servers. The enhancement here would be to support sending files via multipart in WP_HTTP.