librelist archives

« back to archive

Flask + GoogleAppEngine + Blobstore

Flask + GoogleAppEngine + Blobstore

From:
Amirouche Boubekki
Date:
2011-04-10 @ 21:36
Héllo,

Has anyone succeeded at uploading files using the blobstore en GAE ?

Here is the code I use to handle the form and the upload handler:

@app.route('/upload', methods=('GET',))
def upload():
    upload_url = blobstore.create_upload_url('/handle_upload')
    form = UploadForm()
    return render_template('upload.html', upload_url=upload_url, form=form)

@app.route('/handle_upload', methods=('POST',))
def handle_upload():
    form = UploadForm()
    if form.validate_on_submit():
        return redirect('/')
    return redirect('/upload')

the console print this error :

INFO     2011-04-10 21:34:26,234 dev_appserver.py:585] Internal redirection
to /handle_upload
INFO     2011-04-10 21:34:26,241 dev_appserver_blobstore.py:358] Upload
handler returned 302
ERROR    2011-04-10 21:34:26,242 dev_appserver_blobstore.py:373] Invalid
upload handler response. Only 301, 302 and 303 statuses are permitted and it
may not have a content body.
INFO     2011-04-10 21:34:26,248 dev_appserver.py:3951] "POST
/_ah/upload/agNhcHByGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgjDA HTTP/1.1" 500 -


it seems like the content body is set to something but not from my code
since I do a simple redirect.

Any ideas from where the error can come from ?

Thanks in advance.

abki.

Re: [flask] Flask + GoogleAppEngine + Blobstore

From:
zach will
Date:
2011-04-10 @ 21:47
I finally got it working this week. The response can't have any data. Check
out this thread:

http://groups.google.com/group/google-appengine-python/browse_thread/thread/261931ccdb1cdf1a?hl=en

On Apr 10, 2011 4:42 PM, "Amirouche Boubekki" <amirouche.boubekki@gmail.com>
wrote:
>
> Héllo,
>
> Has anyone succeeded at uploading files using the blobstore en GAE ?
>
> Here is the code I use to handle the form and the upload handler:
>
> @app.route('/upload', methods=('GET',))
> def upload():
>     upload_url = blobstore.create_upload_url('/handle_upload')
>     form = UploadForm()
>     return render_template('upload.html', upload_url=upload_url,
form=form)
>
> @app.route('/handle_upload', methods=('POST',))
> def handle_upload():
>     form = UploadForm()
>     if form.validate_on_submit():
>         return redirect('/')
>     return redirect('/upload')
>
> the console print this error :
>
> INFO     2011-04-10 21:34:26,234 dev_appserver.py:585] Internal
redirection to /handle_upload
> INFO     2011-04-10 21:34:26,241 dev_appserver_blobstore.py:358] Upload
handler returned 302
> ERROR    2011-04-10 21:34:26,242 dev_appserver_blobstore.py:373] Invalid
upload handler response. Only 301, 302 and 303 statuses are permitted and it
may not have a content body.
> INFO     2011-04-10 21:34:26,248 dev_appserver.py:3951] "POST
/_ah/upload/agNhcHByGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgjDA HTTP/1.1" 500 -
>
>
> it seems like the content body is set to something but not from my code
since I do a simple redirect.
>
> Any ideas from where the error can come from ?
>
> Thanks in advance.
>
> abki.

Re: [flask] Flask + GoogleAppEngine + Blobstore

From:
Adam Oakman
Date:
2011-04-10 @ 22:24
This has come up indirectly a couple of times on the list previously.  
Here is some sample code.


file_header =  
parse_options_header(request.files['file'].headers['Content-Type'])
blob_key = file_header[1]['blob-key']
blob = blobstore.BlobInfo.get(blob_key)
...
response = redirect(request.values['return'])
response.data = ''
return response

Also the latest App Engine SDK has an experimental API for file  
uploads: 
http://code.google.com/appengine/docs/python/blobstore/overview.html#Writing_Files_to_the_Blobstore

Thanks

A
On Apr 10, 2011, at 4:47 PM, zach will wrote:

> I finally got it working this week. The response can't have any  
> data. Check out this thread: 
http://groups.google.com/group/google-appengine-python/browse_thread/thread/261931ccdb1cdf1a?hl=en
> On Apr 10, 2011 4:42 PM, "Amirouche Boubekki" <amirouche.boubekki@gmail.com 
> > wrote:
> >
> > Héllo,
> >
> > Has anyone succeeded at uploading files using the blobstore en GAE ?
> >
> > Here is the code I use to handle the form and the upload handler:
> >
> > @app.route('/upload', methods=('GET',))
> > def upload():
> >     upload_url = blobstore.create_upload_url('/handle_upload')
> >     form = UploadForm()
> >     return render_template('upload.html', upload_url=upload_url,  
> form=form)
> >
> > @app.route('/handle_upload', methods=('POST',))
> > def handle_upload():
> >     form = UploadForm()
> >     if form.validate_on_submit():
> >         return redirect('/')
> >     return redirect('/upload')
> >
> > the console print this error :
> >
> > INFO     2011-04-10 21:34:26,234 dev_appserver.py:585] Internal  
> redirection to /handle_upload
> > INFO     2011-04-10 21:34:26,241 dev_appserver_blobstore.py:358]  
> Upload handler returned 302
> > ERROR    2011-04-10 21:34:26,242 dev_appserver_blobstore.py:373]  
> Invalid upload handler response. Only 301, 302 and 303 statuses are  
> permitted and it may not have a content body.
> > INFO     2011-04-10 21:34:26,248 dev_appserver.py:3951] "POST /_ah/ 
> upload/agNhcHByGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgjDA HTTP/1.1" 500 -
> >
> >
> > it seems like the content body is set to something but not from my  
> code since I do a simple redirect.
> >
> > Any ideas from where the error can come from ?
> >
> > Thanks in advance.
> >
> > abki.
>

Re: [flask] Flask + GoogleAppEngine + Blobstore

From:
Amirouche Boubekki
Date:
2011-04-11 @ 06:33
>
> Also the latest App Engine SDK has an experimental API for file uploads:
> 
http://code.google.com/appengine/docs/python/blobstore/overview.html#Writing_Files_to_the_Blobstore
>

It written in the documentation :

« This is a low-level API. You can use the high-level mapreduce
library<http://mapreduce.appspot.com/> to
create blobstore files *based on datastore data*. »

I'm not sure we can use it to write files from upload, we should test it.

Thanks for you answers, it worked well with the snippets.

Thanks
>
> A
>
> On Apr 10, 2011, at 4:47 PM, zach will wrote:
>
> I finally got it working this week. The response can't have any data. Check
> out this thread:
> 
http://groups.google.com/group/google-appengine-python/browse_thread/thread/261931ccdb1cdf1a?hl=en
>
> On Apr 10, 2011 4:42 PM, "Amirouche Boubekki" <
> amirouche.boubekki@gmail.com> wrote:
> >
> > Héllo,
> >
> > Has anyone succeeded at uploading files using the blobstore en GAE ?
> >
> > Here is the code I use to handle the form and the upload handler:
> >
> > @app.route('/upload', methods=('GET',))
> > def upload():
> >     upload_url = blobstore.create_upload_url('/handle_upload')
> >     form = UploadForm()
> >     return render_template('upload.html', upload_url=upload_url,
> form=form)
> >
> > @app.route('/handle_upload', methods=('POST',))
> > def handle_upload():
> >     form = UploadForm()
> >     if form.validate_on_submit():
> >         return redirect('/')
> >     return redirect('/upload')
> >
> > the console print this error :
> >
> > INFO     2011-04-10 21:34:26,234 dev_appserver.py:585] Internal
> redirection to /handle_upload
> > INFO     2011-04-10 21:34:26,241 dev_appserver_blobstore.py:358] Upload
> handler returned 302
> > ERROR    2011-04-10 21:34:26,242 dev_appserver_blobstore.py:373] Invalid
> upload handler response. Only 301, 302 and 303 statuses are permitted and it
> may not have a content body.
> > INFO     2011-04-10 21:34:26,248 dev_appserver.py:3951] "POST
> /_ah/upload/agNhcHByGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgjDA HTTP/1.1" 500 -
> >
> >
> > it seems like the content body is set to something but not from my code
> since I do a simple redirect.
> >
> > Any ideas from where the error can come from ?
> >
> > Thanks in advance.
> >
> > abki.
>
>
>