Hi!
Does anybody know if it is possible to upload a base64 encoded file via the API? I've already examined SVGEdit extension by Brion Vibber (http://www.mediawiki.org/wiki/Extension:SVGEdit) to get behind the api file upload magic. But as SVG is just text it doesn't quite fit to my use case.
When I try to upload a base64 encoded file via the API (i.e. a JPEG) I just get a file with the base64 string (i.e. plaintext with base64 code) written to the MediaWiki file repo.
Any hints?
Greetings,
Robert Vogel Social Web Technologien Softwareentwicklung Hallo Welt! - Medienwerkstatt GmbH
[cid:image001.png@01CCE104.F5BC2A10]http://www.cebit.de/aussteller/hallo-welt-medienwerkstatt/V417252 ______________________________
Untere Bachgasse 15 93047 Regensburg
Tel. +49 (0) 941 - 66 0 80 - 198 Fax +49 (0) 941 - 66 0 80 - 189
www.hallowelt.biz vogel@hallowelt.biz
Sitz: Regensburg Amtsgericht: Regensburg Handelsregister: HRB 10467 E.USt.Nr.: DE 253050833 Geschäftsführer: Anja Ebersbach, Markus Glaser, Dr. Richard Heigl, Radovan Kubani
On Wed, Feb 1, 2012 at 5:22 PM, Robert Vogel vogel@hallowelt.biz wrote:
Hi!****
Does anybody know if it is possible to upload a base64 encoded file via the API? I’ve already examined SVGEdit extension by Brion Vibber ( http://www.mediawiki.org/wiki/Extension:SVGEdit) to get behind the api file upload magic. But as SVG is just text it doesn’t quite fit to my use case.****
When I try to upload a base64 encoded file via the API (i.e. a JPEG) I just get a file with the base64 string (i.e. plaintext with base64 code) written to the MediaWiki file repo.****
Any hints?****
**
Are you using a client that generates a MIME multipart POST request for you, or are you doing that yourself? If you're generating one yourself, you can simply use the Content-Transfer-Encoding: base64 header to tell the web server that the file is base64-encoded. If you're using a library or client that builds an HTTP request for you, you'll probably have to decode the base64 encoding and hand the raw file contents to the library/client.
Roan
On Wed, Feb 01, 2012 at 05:22:39PM +0100, Robert Vogel wrote:
Does anybody know if it is possible to upload a base64 encoded file via the API? I've already examined SVGEdit extension by Brion Vibber (http://www.mediawiki.org/wiki/Extension:SVGEdit) to get behind the api file upload magic. But as SVG is just text it doesn't quite fit to my use case.
Since HTTP POSTs may contain binary data, you can send the file without any special encoding. That would usually be the best thing to do.
Theoretically, if you really wanted to base64-encode it you could include a "Content-Transfer-Encoding: base64" header in the MIME part for the file data.[1] But PHP doesn't handle this correctly,[2] so in practice you'll probably need to use 8bit or binary encodings instead.
[1] See RFC 2388 section 3. https://www.rfc-editor.org/rfc/rfc2388.txt [2] https://bugs.php.net/bug.php?id=48219
Roan, Brad, thanks for the quick reply.
A few words about the use case: my colleague has got a java applet that generates an image and provides this image as base64 encoded string via a javascript interface. His javascript code grabs this string and uses the "FormMultipart" class from Brion Vibbers SVGEdit extension (modules/ext.svgedit.formmultipart.js) to send a request to the MediaWiki API. The "Content-Transfer-Encoding: base64" is set. The file that is created in the MediaWiki repo is corrupted.
So long, thanks for the hints. We will keep them in mind.
---
Robert Vogel Social Web Technologien Softwareentwicklung Hallo Welt! - Medienwerkstatt GmbH
______________________________
Untere Bachgasse 15 93047 Regensburg
Tel. +49 (0) 941 - 66 0 80 - 198 Fax +49 (0) 941 - 66 0 80 - 189
www.hallowelt.biz vogel@hallowelt.biz
Sitz: Regensburg Amtsgericht: Regensburg Handelsregister: HRB 10467 E.USt.Nr.: DE 253050833 Geschäftsführer: Anja Ebersbach, Markus Glaser, Dr. Richard Heigl, Radovan Kubani
-----Ursprüngliche Nachricht----- Von: mediawiki-api-bounces@lists.wikimedia.org [mailto:mediawiki-api-bounces@lists.wikimedia.org] Im Auftrag von Brad Jorsch Gesendet: Mittwoch, 1. Februar 2012 18:00 An: MediaWiki API announcements & discussion Betreff: Re: [Mediawiki-api] API: Fileupload with base64 encoded data
On Wed, Feb 01, 2012 at 05:22:39PM +0100, Robert Vogel wrote:
Does anybody know if it is possible to upload a base64 encoded file via the API? I've already examined SVGEdit extension by Brion Vibber (http://www.mediawiki.org/wiki/Extension:SVGEdit) to get behind the api file upload magic. But as SVG is just text it doesn't quite fit to my use case.
Since HTTP POSTs may contain binary data, you can send the file without any special encoding. That would usually be the best thing to do.
Theoretically, if you really wanted to base64-encode it you could include a "Content-Transfer-Encoding: base64" header in the MIME part for the file data.[1] But PHP doesn't handle this correctly,[2] so in practice you'll probably need to use 8bit or binary encodings instead.
[1] See RFC 2388 section 3. https://www.rfc-editor.org/rfc/rfc2388.txt [2] https://bugs.php.net/bug.php?id=48219
_______________________________________________ Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
mediawiki-api@lists.wikimedia.org