Montag, 24. Mai 2010

How to upload files to a MediaWiki using JWBF

This little issue has been nagging me for a while, this is why I post it here hoping it will help others as well.

So if you want to
- upload images to your own (or somebody else's) MediaWiki
and you
- want to do it using java
and
- you happen to use the Java Wiki Bot Framework (aka jwbf)
then this one is for you:

String localPathToFile = "/home/klausbert/tmp/myTestImage.jpg";
String urlToWiki = "http://mydoma.in/wiki/";
String wikiUser = "klausbert";
String wikiPassword = "klausbertsPassword";
String descriptionText = "Some text to describe the image";

MediaWikiBot mwb = new MediaWikiBot(urlToWiki);
mwb.login(wikiUser, wikiPassword);
SimpleFile file = new SimpleFile(localPathToFile);
file.addText(descriptionText);
mwb.performAction(new FileUpload(file, mwb));

Of course you will need some imports and try-catches. But the code is the essence of what you need to upload the file.

1 Kommentar:

  1. Ӏf yοu аre going fοr beѕt contents like I
    do, оnly ѵisit thіѕ ωebѕіte all
    the tіme as it offеrs feature cоntents,
    thanks

    Alsο vіsit my ωeb blog Chemietoilette

    AntwortenLöschen

Hinweis: Nur ein Mitglied dieses Blogs kann Kommentare posten.