New Adobe AIR App: MediaWiki Uploader

As part of the Flex 3 launch I needed to upload about 70 images for the feature introductions. Those of you who use MediaWiki (the wiki system on Labs) may know that it doesn’t support uploading multiple files at once. Each upload to the Labs wiki requires choosing the image via the file chooser and checking a box saying that you own copyright. Rather than do this work myself I decided to see if I still remembered how to code and wrote up a quick app using Adobe AIR so that I could upload lots of images at once. I’m making the app available to you all under the MIT license to do with what you please.

Download the AIR (requires Adobe AIR Beta 1)
Download the source (in theory you should be able to import this as a project into Flex Builder)

This app was interesting to build as it had a few interesting challenges.

1. Don’t you need to be logged in to upload?

Yes! And since this is an AIR application it wasn’t sharing my session with Firefox. So I wrote a login service (HTTPService) to execute the login for me (against my staging server). Easy enough except that it was difficult to tell when things were going wrong due to not wanting to add lots of debugging code to the app. So I used my trusty network sniffer (I used the one that comes with JRun but lots of folks use Wireshark or Charles) to figure out where I was going wrong and got the login working. One thing I noticed was that the response on a successful login (and also upload) to my testing wiki was a 302 redirection which the Player did not follow. However it treated the call as a success, and since I wasn’t going for solid code I let it be.

2. How do you go about uploading the image?

I went to the upload page and looked at the source to figure out the parameters that were needed. Believe it or not, this is my first Flex app where I’ve done file uploading. Fortunately the docs for FileReference.upload were pretty easy to understand. I was able to see most of the variables that I needed to set by looking at the form items and filled in the URLVariables to be sent along with the upload request. I created a DataGrid where you can edit the display name, but I didn’t actually want to change the names so I didn’t even test to see if my changes would have worked.

So now I could upload multiple images to my staging server (I actually did two different staging servers because I didn’t want to corrupt the real staging server). This allowed me to shake out a minor difference between the two so now my system could upload to both. But then I faced my final challenge…

3. The Labs wiki doesn’t use MediaWiki’s account management, it uses adobe.com’s!

Oops! I thought I might have just wasted a few hours of coding since I wouldn’t be able to do my real uploads with my fancy new tool. Then I had a thought…the http session information and cookies are shared between HTML and Flash in AIR. All I need to do is use an HTML control, navigate to the wiki and sign in there, then I don’t need to use my custom login stuff for this particular wiki. So I created a new Window, put an HTML control in there (nice job Gordon!), threw in a TextInput so I could quickly change the location, and away we went. Final complication though is that login on adobe.com is through https but all of the other urls were http. The HTML control didn’t seem to like moving back and forth. So I simply used the TextInput to change to some urls that I knew would work, and despite the fact that sometimes the redirections didn’t work, when I then went to the Labs page I could see I was logged in. Tried to upload a file, and voila!

My new HTML window gave me an extra bonus, I could now check the wiki’s recently added images special page to ensure that everything was getting up there OK.

Note that this was really written as a utility for me, so I made no usability fixes. The wiki url must basically be the root of the wiki with no trailing slash: e.g., http://labs.adobe.com/wiki/index.php. I don’t do any corrections if the url is invalid. And there is no error handling whatsoever. If someone was interested in making it more robust I’d be happy to link to your verision (or repost it).