Making a better Flickr Web Uploadr (Or, “Web Browsers Aren’t Good At Uploading Files By Themselves”)

Sometimes when browsers won’t do what you want by themselves, you have to get creative.

A Brief History Of Web Uploading

As any developer who’s suffered through form-based uploading will understand, browsers have very limited native support for selecting and uploading files. While useable, Flickr’s form-based upload needed a refresh that would allow for batch selection and other improvements. After some consideration, Flash’s file-handling capabilities combined with the usual HTML/CSS/JS looked to be the winning solution.

In the past, ActiveX controls and Firefox extensions provided enhanced web-based upload experiences on Yahoo! Photos, supporting batch uploads, per-file progress , error reporting and so on; however, the initial browser-specific download/install requirement was “just another thing in the way” of a successful experience, not to mention one limited to Firefox and Internet Explorer. With Flickr’s new web Uploadr, my personal goals were to minimize or eliminate an install/set-up process altogether whenever possible, while at the same time keeping the approach browser-agnostic. Because of Flash’s distribution amongst Flickr users, it was safe to have as a requirement for the new experience. (In the non-flash/unsupported cases, browsers fall through to the old form-based Uploadr.)

And Now, For Something Completely Different

By using Flash to push files to Flickr, a number of advantages were clear over the old form-based method:

  • Batch file selection
  • File details (size, date etc.) for UI, business logic
  • Improved upload speed (faster than native browser form-based upload)
  • “Per-file”, asynchronous upload (as opposed to posting all data at once)
  • Upload progress reporting (per-file and overall)

Flash is able to do batch selection through standard operating system dialogs, report file names and size information, POST file data and read responses. Flickr’s new web Uploadr uses these features to provide a much-needed improvement over the old form-based Uploadr. The Flash component was developed by Allen Rabinovich on the Yahoo! Flash Platform Team. http://developer.yahoo.com/flash/

This Flash-based upload method did come with a few technical quirks, but ultimately we were still able to make signed calls to the Flickr API and upload files.

Now You Can, Too!

The Flash and client-side code which underlies the Flickr Web Uploadr is part of the Yahoo User Interface Library, available as the YUI Uploadr component.

It’s The Little Things That Count: UI Feedback

Given that Flash reports both file size and bytes uploaded, it made sense to show progress in the UI. In addition to per-file and overall progress in-page, the page’s title as shown in a browser window or tab also updates to reflect overall progress during upload – for example, “(42% complete) Flickr: Upload Photos”

Under Firefox, an .GIF-based “favicon” replaces the static Flickr icon, showing animation in the browser address bar while uploading is active. This combined with the title change is a nice indication of activity and status while the page is “working”, a handy way of checking progress without requiring the user to work to bring the window or tab back into focus.

In showing attention to detail in the UI and finding creative solutions to common browser drawbacks, a much nicer web upload experience is most certainly possible.

Scott Schiller is a front-end engineer and self-professed “DHTML + web standards evangelist / resident DJ and record crate digger” who works on Flickr. He enjoys making browsers do nifty things with client-side code, and making designers happy in bringing their work to life with close attention to detail. His personal site is a collection of random client-side experiments. http://flickr.com/photos/schill/

Flickr Uploadr, start to finish now

Starting at Flickr a short nine months ago, I was given the state of the Flickr Uploadr and told to make it better. Better meant many things. It meant cross-platform so we could move forward with one codebase. It meant localized in all of Flickr’s languages without hackery. It meant new features that would make uploading easier and encourage people to add metadata to their photos. And while we didn’t explicitly talk about it at the time, better meant open source.

Settling on a platform

Straight C? No. Java Swing? Adobe AIR? XULRunner? So many choices, each with advantages and disadvantages. I ended up choosing to work with Mozilla’s XULRunner, which is what makes up the guts of Firefox and Thunderbird. The main advantages of XULRunner were the ability to link in outside code libraries (like GraphicsMagick) and the availability of real multithreading.

Learning the hard way

Since the project began I’ve jumped more than a few hurdles. I documented many of the more exciting problems on my blog (rcrowley.org) as I went. Crash course follows:

Cross-platform XPCOM (a howto)

Working from Mark Finkle’s crash course for Windows got me halfway and some other scattered resources helped to piece together the skeleton of an app that will run on both Windows and OS X. The code has evolved quite a bit since then but this process got me on my feet.

XUL overlays demystified

As apps grow you naturally need to break files up to save your sanity. I never found the crystal clear example of overlays that I wanted, so after I trial-and-errored my way out of the corner, I wrote out this common use case that Uploadr uses in several places.

Threading in Gecko 1.9

I’ve been developing against XULRunner 1.9 (and therefore Gecko 1.9) which are the underpinnings of Firefox 3. The thread primitives made available in 1.9 are much nicer than in Gecko 1.8. Uploadr uses a background thread for event queuing and this is a stripped down example of that same pattern.

MD5 in XULRunner (or Firefox extensions)

The Flickr API requires developers to sign calls with MD5. MD5 is built right into PHP but is conspicuously missing from JavaScript. There are JavaScript implementations out there but (just for kicks), here’s how to take advantage of Mozilla’s built-in hashing library.

Fun with Unicode!

Flickr has, from the very beginning, been an international place. Well before it was available in eight languages, it would accept user input in any language through the magic of UTF-8. Uploadr carries on this tradition but to bridge the gap between Windows’ UTF-16 Unicode support and GraphicsMagick’s non-Unicode-iness, some hacks had to be liberally applied. This code has changed a bit since, so check the latest out in Flickr Subversion.

Video interview with the Yahoo! Developer Network

Jeremy Zawodny from the Yahoo! Developer Network came up to San Francisco to chat about the new Flickr Uploadr a few months back. We talked about the development process, open source and where the future might lead.

The future is here now with an extension API ready for use in version 3.1. Check out the documentation and helloworld extension or check out the full source code and build tools.