views:

95

answers:

1

We provide the ability to submit images to a user's gallery.

While the normal method we have employed works just fine, some people will upload multiple files, which can take a long time, and is annoying in the selection process (one at a time).

I started writing an alternate method using Gears for those that have it. Primarily the goal is to replace the file selection, and provide a progress indicator for the upload (which helps mitigate the frustration when uploading multiple big files).

I have all this done.

I referenced the Movie Uploader code here (http://uploadmovietool.appspot.com/) which demonstrates uploading files using the chunk method. I have it uploading correctly, the server is accepting the chunks, however I am running into a problem trying to handle the incoming data with PHP.

Each chunk is a seperate request to the script, and none of the data is registered in PHP's normal incoming data vars _POST,_GET,_FILES, etc. I have finally been able to get the data from sucking on $GLOBALS['HTTP_RAW_POST_DATA'] however even when appending the data onto the same file, the image is never complete. It will show portions, but something is always wrong.

..That being said.. if there is an easier way to post files to the script, while still having access to progress updates, I would love to hear it.

When I started this project, I had assumed that Gears would provide me with a way to do multipart post with files like normal, and simply give me an event fire on an interval with progress information. If this is somehow possible (and I've obviously missed it), please let me know.

To be clear: We are aware that HTML5 supports progression mechanics, and are prepared to implement based on it as soon as it is viable. :)

For further reference:

The headers that I'm sending with the post (as per the google movie uploader example) are:

Request.setRequestHeader( 'Content-Disposition', 'attachment; filename="' + self._fileName + '"' );
Request.setRequestHeader( 'Content-Type', 'application/octet-stream' );
Request.setRequestHeader( 'Content-Range', 'bytes ' + byteRange );

Thanks to anyone who can help.

A: 

From your description it looks like PHP may not be writing the file correctly.. Not sure why.

However, this is a sticky problem. For instance, Facebook (who also uses PHP as you know) settled on writing an NPAPI plugin to implement this feature.

http://www.facebook.com/note.php?note_id=178492968919

Also, you could consider the less portable option of writing browser extensions. This is quite easy to do in Firefox and Chrome, and would give you a good temporary option for users of those browsers.

Kris Walker
Thanks for the response. Unfortunately, asking our users to install a plugin just for our property is not an option we are willing to pursue. I would be more willing to just use a flash uploader as opposed to a plugin.
Spot