Fwing Photo Upload MIDlet for 6600 and 6680
Sunday, July 17th, 2005One of my long standing pet peeves is that I can’t set tags when I send a photo from my phone. There were some postings a while ago about a MIDlet that posted to Flickr, but I couldn’t find it. And I haven’t written any MIDP code since early 2003. That’s a long time ago in Internet time. It translates on the Great Internet Timeline scale to somewhere around the Tiassic period. I really needed a quick refresher. So I fixed both problems by making a MIDlet that uploads images to Flickr using the POST based API. It’s ugly, it’s full of bugs, it doesn’t start up right the first time you try it, it can’t capture images unless there’s practicly nothing else running. But for me at least it works. So I’m going to invoke the “Release early, release often” mantra and just toss this one out there. If you want to give it a shot download here. Here are the basic steps for use:
- Start the app and bring up the settings form. You might have to start and exit and start again the very first time in order to get it to work correctly. There’s probably a problem there with the values for the defaults… I would test it out and find the bug. But that means uninstalling it to clear the record store, reinstalling to test out a fix, uninstalling again to retest. You see the problem there? The whole thing smacks of effort.
- Fill in your username (that’s your email) and your password. Fill in the defaults with new values if you want. Please keep the “fwing” tag as part of the tagset you use. You don’t have to, but consider this a kind request from the guy who released the project. I want to see how many people use this.
- Go back to the main form and fill in the title, description, and tags you want to use. Remember to please keep the fwing tag, see above.
- Select capture to go to a camera preview screen.
- Once you have a picture you like framed select capture again to snapshot it. Pressing in on the joystick should capture an image as well. But look at that, it doesn’t! It used to do that in the original sample from Nokia, but that one only captured images at 160×120. I’m sure it could be added back in. That is, it is theoretically possible to add it back in. The theory does not account for my laziness however. I’ve found that to be a general issue with theories.
- Select send if you want to send the image to the server, or back if you want to grab a different image. There should be a progress dialog there to let you know how far along it is. But the upload can take a long time, and I was sure people would get bored. So I included a little mini-game. It’s called “Guess How Long the Upload Takes”, and you play by staring at the screen until the info dialog comes up informing you of success or failure. You can even play multiplayer using a single handset!
You can keep looping and capturing and sending images with the same set of tags and description/title. That’s about all it’s good for, cause that’s what I normally do. You don’t like it? Think it should allow you to return to the top level and tweek description for each photo? Think there should be an option to pull images from the filesystem? Think it should spool images and upload in a batch? Think the bugs are too annoying to deal with? Good. This is the code for the initial version, download it and fix it yo’ damn sef. If you want to be really cool, send me patches or release your version and send me a note. License is GPL.
I’ve personally tried this out on the 6680 and the 6600, and it works on both. I’m assuming it should work with the 6620 and maybe a few other models. The image source is the back camera on the 6680. I have yet to find a way to capture from the front camera via Java. Images are captured at 640×480, try for any larger and the snapshot call consistently returns an exception. Not that I’m a Java programmer or anything, but there are some bits of code which may be of interest to some folks:
- I had heard that the image resolution for captured images on the 6600 had to be the same as the display resolution when you’re working in Java. Not true. If you initDisplayMode() on the VideoControl with USE_DIRECT_VIDEO then just about any parameters you pass to getSnapshot() either cause an exception or get ignored. But if you init with USE_GUI_PRIMITIVE then you can getSnapshot() in the size you want. Well, not quite the size you want. I can’t get a full rez 1.3 megapixel image from the rear camera on the 6680, and I REALLY WANT ONE! The code I started with came from a sample on the Nokia site.
- The 640×480 image is resized to 160×120 using a quick hack of an image downsampling routine I found online. Check out the scaleImage() routine in DisplayCanvas. It takes an immutable image and a width and height, and returns another image with the given size. J2ME doesn’t have an image resize available as far as I can tell, so that little routine might find it’s way into my standard toolkit.
- The submission to Flickr is done as a multipart form POST. There’s a horrifically simple cover called MultipartHttpConnection that covers HttpConnection. Create the class giving it the URL to use, then you can addParam() and addFile() as necessary, and send() it when you’re done. I tend to do a metric buttload of server interaction on just about every project, and if it’s not XML it’s multipart forms. So that one is probably another keeper.
