Hello,
I try to upload files via the API using Javascript and it's File API
(for the latter, see e.g.
http://www.html5rocks.com/en/tutorials/file/dndfiles/)
However I have been not successful in getting it working and so were
fellow users (see e.g.
https://www.mediawiki.org/wiki/API_talk:Upload#REAL_WORLD_EXAMPLES_.3F.3F.3F)
Using my current approach, I always get a " One of the parameters
filekey, file, url, statuskey is required", despite the fact that the
file is defined.
I used jQuery, doing the following request:
formdata = new FormData();
formdata.append("action", "upload");
formdata.append("filename", fileName); //name of the file as string
formdata.append("token", myEditToken); //edit token retrieved via var
myEditToken = mw.user.tokens.get( 'editToken' );
formdata.append("file", fileToUpload); //file read via File Api using
readAsBinaryString(file)
$.ajax( {
//http://stackoverflow.com/questions/6974684/how-to-send-formdata-objects-with-ajax-requests-in-jquery
url: mw.util.wikiScript( 'api' ),
contentType:false,
processData:false,
type:'POST',
data: formdata, //formdata: see
above the $.ajax for its definition
//success and error functions here,
but deleted for the sake of brevity.
});
Could you possible help me by telling me why the upload is not
succeeding and do you know a (Javascript based) solution for the problem?
Kind Regards,
Jan
Hi, All!
I found a very strange thing about the continue tokens:
The link is here:
http://commons.wikimedia.org/w/api.php?action=query&format=xml&revids=37692…
I got the following response:
<api>
<query>
<pages>
<page pageid="1246719" ns="6" title="File:AB towns+names.png"
imagerepository="local" contentmodel="wikitext" touched="
2012-04-26T19:25:33Z" lastrevid="37692183" counter="" length="447">
<categories>
<cl ns="14" title="Category:Locator maps of cities in Alberta"/>
<cl ns="14" title="Category:Maps of Alberta"/>
<cl ns="14" title="Category:PD-self"/>
</categories>
<imageinfo>
<ii size="82937" width="524" height="700" url="
http://upload.wikimedia.org/wikipedia/commons/1/1d/AB_towns%2Bnames.png"
descriptionurl="http://commons.wikimedia.org/wiki/File:AB_towns%2Bnames.png"
sha1="0753be62082948bceb1db4205e75d4cf819dbbfa"mime="image/png" bitdepth="8
"/>
</imageinfo>
<revisions>
<rev revid="37692183" parentid="25300971" minor="" user="Qyd" timestamp="
2010-04-16T02:38:20Z" comment="/* {{int:filedesc}} */ gallery" contentformat
="text/x-wiki" contentmodel="wikitext" xml:space="preserve">
== {{int:filedesc}} == {{Information |Description=Map of [[Alberta]] with
cities, towns and roads |Source=GIS data |Date=2006-10 |Author={{User|Qyd}}
|Permission=All |other_versions=<gallery> Image:AB-towns-roads.png|without
town names Image:AB-towns-highways.png|simplified
Image:AB-cities-roads.png|cities and highways </gallery> }} [[Category:Maps
of Alberta]] [[Category:Locator maps of cities in Alberta|*]] ==
{{int:license}} == {{PD-self}}
</rev>
</revisions>
</page>
</pages>
</query>
<limits categories="500"/>
<continue continue="||categories|info|revisions" iistart="
2006-10-05T10:33:30Z"/>
</api>
I found there was a continue token at the end of the response, Then I use:
http://commons.wikimedia.org/w/api.php?action=query&format=xml&revids=37692…<http://commons.wikimedia.org/w/api.php?action=query&format=xml&revids=37692…>
to get the following response:
<api>
<limits categories="500"/>
<query>
<pages>
<page pageid="1246719" ns="6" title="File:AB towns+names.png"
imagerepository="local">
<imageinfo>
<ii size="76966" width="524" height="700"url="
http://upload.wikimedia.org/wikipedia/commons/archive/1/1d/20061006020043%2…
"descriptionurl="http://commons.wikimedia.org/wiki/File:AB_towns%2Bnames.png
" sha1="387284aaeea43dfae091e965e19cc47ce99dcf49"mime="image/png" bitdepth="
8"/>
</imageinfo>
</page>
</pages>
</query>
<continue continue="||categories|info|revisions" iistart="
2006-10-04T23:32:38Z"/>
</api>
I found in the response we didn't have the revisions information any more.
I think this may be a bug? Because I found if we set clcontinue to request
the following page, the response will not miss the revisions information.
P.S. Another question: Are the items in imageinfo list sorted by timestamp?
I mean from latest to oldest.
Thanks.
Hey, just wanted to share the fruits of some Mediawiki API work....
www.mapedia-uk.net
Try doing a search in the Historical types, such as British Prehistory or Roman Britain. Search for these in the UK and the locations you'll find there are Wikipedia articles that feature locations.
Still a WIP, with some teething problems in our system. But.. It does work :)
any feedback welcome,
Cheers
Chris Thomas - Managing Director
chris(a)mapedia-uk.net