wp_remote_post with file payload

Viewed 1299

I'm attempting to POST a file through wp_remote_post. Unfortunately, any file stream, or file paths (prepended with CURL style @, or not), passed to this function are simply dropped and removed from the payload.

I found a post on wp-hackers, however, it's extremely hack-ish and error prone. Is there really no way to transmit a file through this function without writing a complete HTTP payload from scratch?

Here's an example code block using CURL style (prepending path with @), if interested:

    $body["attachment[{$i}]"] = "@{$attachment}";

    $data = array(
    'body' => $body,
    'headers' => array(
        'Authorization' => 'Basic ' . base64_encode( "user:{$apiKey}" )));

$url = "https://api.someservice.net/{$domain}/endpoint";
$response = wp_remote_post( $url, $data );

Thanks!

1 Answers
Related