Upload to a remote server using wp_remote_post

I’am developing a plugin that will push files to a remote server via http upload. Currently I got it to work with CURL doing something like this:

$post = array("post_file"=>"@/path/FILE.EXT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 

Now my question is how I can achieve the same using wp_remote_host. How is the file included in the ‘body’ argument.

Read More

For more info see this.
http://codex.wordpress.org/Function_API/wp_remote_post

Related posts

Leave a Reply

2 comments

  1. Something like this, perhaps.

    $args['body'] = array('post_file'=>'@/path/FILE.EXT');
    wp_remote_post($url, $args);
    

    The $args array contains the parameters for the post. The body parameter controls what is posted. There’s many other possible parameters as well. See http://codex.wordpress.org/HTTP_API#Other_Arguments

    Note that the @file method may be specific to curl, and might not work with the other possible HTTP transports that WP supports.

  2. I read through the source code in wp-includes/class-http.php and wp_remote_post() doesn’t support sending files. I think you’d need to re-write the WP_Http class to make this work or otherwise write a plugin or extension to handle this.