cgt / go-mwclient

A Go package for interacting with the MediaWiki API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Uploading Files

WillNilges opened this issue · comments

Big fan of this library. Is there any chance you might add a way to upload files?

Thank you. Have you had a look at the MediaWiki API docs for uploading files? https://www.mediawiki.org/wiki/API:Upload I think the Post method would work fine for making upload requests. The only caveat is that file uploads must be sent as multipart/form-data and go-mwclient only uses that format for requests with sufficiently large (>8K) fields. If you try to upload an image smaller than that, it would try to send the request as application/x-www-form-urlencoded. Perhaps working around this issue would be a good reason to add a special method for uploading files to go-mwclient. Alternatively, I could change it to always use multipart/form-data for POST requests. I don't see any downsides to doing that. Still, it could be useful to have a method like Upload(params params.Values, file io.Reader) error as a convenience.