[wp-hackers] WP_Http File Upload

Jacob Santos wordpress at santosj.name
Thu Nov 19 06:50:28 UTC 2009


Aaron,

File handling is not handled by default, which you know. This might be 
an interesting extension, as I believe cURL has a specific use case for 
this and so does the HTTP extension. It would be nice to take advantage 
of those extensions functionality for this purpose. When you start to 
get into the other "transports" then it gets ugly, really really ugly. 
As in, "Oh dear god, now I remember why I didn't do it in the first 
place," ugly.

It is something I want, so if Dion Helse (dd32) or another hasn't 
already, then I believe I might take it up. If you are attempting to 
POST to a server that uses PHP and expects it to be compatible with PHP 
Upload, then I'm pretty sure that it is not currently supported by the 
HTTP API in WordPress at this point. You would have to do a bit of 
hacking to add support for cURL and the HTTP API.

Um, I won't be able to get to this until the weekend, but after a bit of 
research it appears simple enough. Ha ha, oh man, famous last words, 
soon I'll be screaming and then the fun will start. I kid. The currently 
problem is that the multipart/form-data is not supported at all and 
completely breaks most of what the current implementation assumes about 
the HTTP request. It will require creating new transports for just 
supporting multipart headers or adding the functionality to support 
multipart headers. Actually, it becomes increasely difficult because you 
have to add up all of the content for the main header and then for all 
of the other headers. So you would have to create the multipart headers 
and base64 the files and get the length and then attempt it again.

Probably also, the multipart can be made to attempt sending up to 8MB to 
see if that works and then split the files into 8MB chunks after if 
multiple files are used. The execution time for this would be crazy 
long, so might be better to just AJAX it instead and send one file at a 
time. It is also possible to check the execution time (for those that 
support it) and then stop with a message of which files were transferred.

Sounds like fun. Just hope someone else doesn't beat me to it.

For now, it doesn't seem like this will be something that will go into 
2.9, maybe 3.0. 2.9 is already beta and I'm unsure if they're going to 
put something so experimental and unstable into something so close to 
being released (2.9.1 maybe?). Given that very few are ever going to use 
this feature, it may not matter. Also, if it is requires more than 4 
hours of work, then I'll have to cut it to two weeks (weekends).

The cURL code is simple enough and you could attempt to use the HTTP 
Extension (even more simple) for now until it is supported for reals in 
WordPress.

Jacob Santos

Aaron Brazell wrote:
> I'm working on a project that requires HTTP file uploads via POST. Does
> anyone (Jacob?) know how the request should be written using the WP_Http
> class? There doesn't seem to be any code that handles file uploads, but I'm
> hoping I don't have to write an extender class just for that use case.
>
> Help?
>
> Aaron Brazell
> CEO, Emmense Technologies
> Lead Editor, Technosailor.com
> Author, The WordPress Bible
>
> e: aaron at technosailor.com
> b: http://technosailor.com
> t: http://twitter.com/technosailor
> p: 443-455-1056Aaron Brazell
> web:: www.technosailor.com
> phone:: 410-608-6620
> skype:: technosailor
> twitter:: @technosailor
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>   


More information about the wp-hackers mailing list