views:

3

answers:

0

So here's my working code to upload a file:

class UploadFormHandler(webapp.RequestHandler):
    def get(self):
        upload_url = blobstore.create_upload_url('/upload')
        path = os.path.join(os.path.dirname(__file__), r'templates/upload_form.html')
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write(template.render(path, {"upload_url":upload_url}))

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        # 'file' is file upload field in the form
        upload_files = self.get_uploads('file')  
        # maybe in this line i want to add something that limits file size and type (mime) ..ie image, mp3 etc.. that is my question - how
        if upload_files:
            blob_info = upload_files[0]
            self.redirect('/serve/%s' % blob_info.key())
        else:
            self.redirect("/uform")

Any ideas?