[wp-hackers] POSTing a file via wp_remote_post

David Anderson david at wordshell.net
Fri Jan 11 11:36:15 UTC 2013

I'm creating a WordPress consumer for the PHP DropBox API 
(https://github.com/benthedesigner/dropbox). This will allow using that 
API toolkit inside a WordPress plugin, and being able to use 
wp_remote_post function for widest compatibility. (The API toolkit 
presently only has a Curl consumer).

This is working for basic POST requests. That was easy; when passed an 
array of things to POST, I send them along to wp_remote_post.

However, when it comes to uploading files, the DropBox API kit is 
passing me arrays like this. Notice the array entry for file:

     [filename] => myfolder/myfile.zip
     [file] => @/path/to/myfile.zip;filename=myfolder/myfile.zip
     [filename] => myfolder/myfile.zip
     [oauth_consumer_key] => (snip)
     [oauth_signature_method] => PLAINTEXT
     [oauth_token] => (snip)
     [oauth_version] => 1.0
     [overwrite] => 1
     [oauth_signature] => (snip)&1d6uqpi59mux2hn

That array entry is keyed for Curl, which can takes entries pre-pended 
with @, and uses the file data from the indicated file (see 

My consumer needs to detect that case, and convert it into the proper 
arguments for a call to wp_remote_post.

Unfortunately the parameters for wp_remote_post are not well documented. 
Reading the source code, it looks like the argument 'stream' could be 
something to do with what I want. That appears to stream a file. But 
then what about the other parameters that needing posting too? How can I 
achieve what Curl is achieving, but using wp_remote_post? (Reading the 
whole file into memory is not an option - it could potentially be more 
than available memory).

Can anybody give me a hand?

Thank you,

WordShell - WordPress fast from the CLI - www.wordshell.net

More information about the wp-hackers mailing list