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... 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