(Untitled)
So I’ve been wanking up a new upload system for Fakku — basically one that lets Jacob et all to just upload a zip file and attach metadata all through a webform (inb4 uploading large files over HTTP is silly) and it automatically unpacks the archive and uploads the data to the appropriate servers. It’s a pretty straightforward thing, except for fucking progress bars.
When I read through the project specs the progress bar raised a red flag. There simply isn’t any standardized way to query the current status of an upload. As far as I see, there’s only two ways to do it –
- Use flash to do the upload.
- Have the webserver provide a JSON interface to query.
The first is fucking stupid — I hate flash.
The second is much more reasonable. The idea is that the browser provides a random key in part of the POST data to identify the upload uniquely. The web server then provides a JSON endpoint to query the status of uploads by the client-specified key. Naturally, this is a pretty straightforward thing and there are implementations available for various servers. Unfortunately, Fakku is running lighttpd-1.4.x which has no such implementation. There’s a mod_uploadprogress for 1.5, but 1.5 is a worthless broken piece of shit.
Anyway, the reason 1.4 doesn’t have an upload progress module is apparently Lighttpd buffers requests before sending them to a backend. This seems like a stupid reason to me. Why the hell would that prevent the web server from providing transfer information to the client? The backend has absolutely nothing to do with the transfer of POST data.
Before writing a full-blown Lighttpd module to implement this, I took a look at how Lighttpd actually handles the buffering of uploaded data. I have to say, it’s pretty hacky. It stores the data in /var/tmp/lighttpd-upload-* (with names generated via something like tempnam). It splits large files into many 1MB buffers.
So I hacked together a PHP script which provides two JSON methods — one to acquire the name of the most recently modified (I wish POSIX let me query file creation time) Lighttpd upload buffer, and another to look up the current size of a buffer based on it’s name. This results in a shitty interface which allows you to basically track how much data you’ve uploaded, except the transfer isn’t linked to the client so it’s got a race condition by design. And you can’t determine the full size of the upload — you only get amount uploaded so far (so you couldn’t implement a progress bar or ETA).
But I’m willing to bet it wouldn’t be impossible to write a Lighttpd module which provided an interface to query this shit. Dunno if I’ll get around to hammering it out though; Lighttpd modules are a pain in the dick to code — there’s close to no documentation aside from other existing modules.
Bleh.
4 comments