Hey,
I have an extension that transfers content, including images, from one wiki to another via the API. Currently it's using the upload via url option [0], which works great, but not obviously not for source wikis that can not be accessed from where the target wiki is. For that I need to use the regular file transfer, but can't find what to do here.
The documentation states very helpful "When uploading files directly, the request must use multipart/form-data as Content-Type or enctype, application/x-www-form-urlencoded will not work.", but then provides no clue at how to actually set the content type when making a request via the MWHttpRequest class. I tried several things after looking at the source, but could not get it working. Also am not finding any existing code doing this.
Any pointers here would be greatly appreciated :)
[0] https://secure.wikimedia.org/wikipedia/mediawiki/wiki/API:Upload#Uploading_f...
Cheers
-- Jeroen De Dauw http://www.bn2vs.com Don't panic. Don't be evil. --
On Thu, Feb 17, 2011 at 3:50 PM, Jeroen De Dauw jeroendedauw@gmail.comwrote:
The documentation states very helpful "When uploading files directly, the request must use multipart/form-data as Content-Type or enctype, application/x-www-form-urlencoded will not work.", but then provides no clue at how to actually set the content type when making a request via the MWHttpRequest class. I tried several things after looking at the source, but could not get it working. Also am not finding any existing code doing this.
Not sure you can at the moment... PhpHttpRequest forces the Content-Type header to application/x-www-form-urlencoded. CurlHttpRequest doesn't seem to, but offhand I don't know whether it knows how to do multipart encoding automatically from key-value pairs as the post data if you set the Content-Type header manually.
Those classes probably need a little tweaking to support multipart.
(Some quick background: HTML forms can be submitted using either 'application/x-www-form-urlencoded' style which basically just shoves a query-string into the POST body instead of on the URL -- or 'multipart/form-data' which uses a variant of MIME multipart document structure to list key-value pairs with additional metadata like type, size, optional filenames etc. File upload controls are the only thing in regular HTML forms that require the multipart system, and the PHP infrastructure will only slurp in files if they're provided that way. At the HTTP client level, the difference between the two is only in the HTTP 'Content-Type' header and the formatting of the POST body contents. Libraries like CURL sometimes provide handy methods to do the formatting for you from arrays of key-value pairs.)
-- brion
* Jeroen De Dauw jeroendedauw@gmail.com [Fri, 18 Feb 2011 00:50:48 +0100]:
Hey,
I have an extension that transfers content, including images, from one wiki to another via the API. Currently it's using the upload via url option [0], which works great, but not obviously not for source wikis that can not be accessed from where the target wiki is. For that I need to use the regular file transfer, but can't find what to do here.
The documentation states very helpful "When uploading files directly, the request must use multipart/form-data as Content-Type or enctype, application/x-www-form-urlencoded will not work.", but then provides
no
clue at how to actually set the content type when making a request via the MWHttpRequest class. I tried several things after looking at the
source,
but could not get it working. Also am not finding any existing code doing this.
Any pointers here would be greatly appreciated :)
[0]
https://secure.wikimedia.org/wikipedia/mediawiki/wiki/API:Upload#Uploading_f...
Cheers
I do use Snoopy php library for multipart/form-data in my Extension:WikiSync. I also use it as a proxy to bypass remote AJAX call security restriction (because my extension was originally used with IE which does not support CORPS and I don't like JSONP and also it's probably unsuitable for posting). Dmitriy
wikitech-l@lists.wikimedia.org