views:

512

answers:

2

I have been trying to use an ajax-style file upload component (like the dojox file upload component) with google app engine, and have a progress bar.

The javascript side of things is fine, but i am wondering how to organise things on the server side?

Is is possible to access the data as it is being uploaded within google app engine, something with BaseHTTPServer perhaps? I could then poll this from the client.

Even if it wasn't possible to do the progress, at least it would be great to be able to terminate a large file and let the user know it was to big without making the user upload 1MB (the google app engine limit) and then find out it was to big.

There are some similar questions: Similar stack overflow question 1, Similar stack overflow question 2.

The following google app engine python code is just the basic post handler for a simple file upload (which works fine) but im looking for something that operates at a bit of a lower level. By the time the post handler gets it, the file has all been uploaded.

On a LAMP stack you can poll a server side script that watches a temporary file size grow. When the file is moved from the temporary folder you know its completed. By using this method you can see the progress of multiple files without the use of flash, I'm not sure how to do the same thing with google app engine.

class fileupload(webapp.RequestHandler):
"""
"""
def post(self):
 if "image" in self.request.arguments():
  content = "<html><body>Error</body></html>"      
  form = self.request.params['image']
  logging.info(form)
  try:
   filename = form.filename
   siz = len(form.value)

   ###--- Show data
   logging.info("Filename: %s" % form.filename)
   logging.info("Size: %s" % siz)

   content = "<html><body>File has been uploaded Name: %s Size: %s</body></html>" % (filename, siz)
   logging.info("DONE")
  except:     
   logging.info("Error: bad form or something like that")

  logging.info("writing out response")
  self.response.out.write(content)
+1  A: 

You can limit file size on a client site using swfupload.

It's a flash component with javascript api that exposes flash uploading capabilities. The check of a file size is done in the client browser. (in function CheckFileSize)

The library has also other goodies like progress bar, check it home page for full feature list.

Piotr Czapla
Thanks, i like the look of swfupload, and there are a few other nice flash upload like http://www.uploadify.com/ and http://www.webappers.com/2007/07/08/fancyupload-beautiful-flash-and-ajax-upload-widget/ I was hoping to get an ajax solution working.
daniel
+1  A: 

App Engine won't return any data from the request handler until the after the request is completed, so any progress checking would have to be done client-side. IIRC your request won't even be loaded into the application server until the upload is complete.

Brandon Thomson
thanks, oh well - one of the limitations of app engine i guess.
daniel
No, no HTTP based upload can report progress without a client-side helper application.
jmucchiello
Might be a good idea to clarify in the answer that this isn't unique to App Engine - it's just how HTTP works.
Nick Johnson