[wp-hackers] POSTing a file via wp_remote_post
David Anderson
david at wordshell.net
Fri Jan 11 12:10:56 UTC 2013
> The various parts there need to be converted into their HTTP
> representations. The OAuth parts should be parsed by an OAuth library
> into an Authorization header.
The DropBox PHP toolkit (https://github.com/benthedesigner/dropbox) is
already doing that bit for me.
I'm just writing the HTTP consumer. The toolkit calls into my function
with a URL and a number of POST fields. All I need to do in my function
is perform the HTTP POST operation.
> Something like this would probably work:
>
> $auth_header = ''; // use OAuth library here to generate this
> $response =
> wp_remote_post('https://api-content.dropbox.com/1/files/.../...?overwrite=1',
> array(
> 'stream' => '/path/to/myfile.zip',
> 'headers' => array(
> 'Authorization' => $auth_header,
> 'Content-Disposition' => 'attachment; filename=myfolder/myfile.zip'
> ),
> );
The toolkit is expecting my consumer to POST all the values it sends, as
the body. So I can't use the above method, because I'm not just POST-ing
the file; I'm POST-ing a number of parameters, and the file is one. Curl
handles this by a special parameter. But I need to be able to stream the
file as *part* (but not the whole) of a stream, using wp_remote_post...
I suppose one thing I could do is create a new file, but that'll bring
me other problems (I'm dealing with potentially huge files in a plugin
that may be used by people in all kinds of situations).
David
More information about the wp-hackers
mailing list