3

Hi I have another question in app engine. You have one form where there's one field for file upload, I need to read the uploaded file, validate it and store it into the datastore.

My question is how can I read the uploaded file?

In django I would have used request.FILES, in GAE is there anything of that sort?

I'd appreciate any help on this

Juan Gomez
  • 1,508
  • 1
  • 11
  • 21
Srinivas HN
  • 197
  • 3
  • 15

2 Answers2

2

this question has been answered in Upload files in Google App Engine

the google app engine documents also explain it. http://code.google.com/appengine/docs/images/usingimages.html#Uploading

In brief, you just need to use self.request.get('name_of_file_in_the_input_form')

Community
  • 1
  • 1
lucemia
  • 6,349
  • 5
  • 42
  • 75
0

One good example for uploading and serving files for Google App Engine is available here. There're at least 3 ways: blodproperty, blobstore write file and blobstoreuploadhandler. While blobstorehandler is not the easiest to implement I do recommend it since it's the natural choice when input is from a form. You pass the upload URL to the request object:

 self.render_template("upload.html", {
    'form': form,#optional if you have a form class
    'form_url': blobstore.create_upload_url('/fileupload'),
})

class FileUploadHandler(blobstore_handlers.BlobstoreUploadHandler):
  def post(self):         
    try:
        if self.get_uploads()[0]:
            blob_info = self.get_uploads()[0]
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424