A simple error occurred while calling Blob, I wrote:
db.get("2I9oX6J0U5nBCVw8kEndpw==")
and instead there was a correct call:
blobstore.get("2I9oX6J0U5nBCVw8kEndpw==")
For those who are looking for a complete download / service image through GAE Blobstore and Flask without using Webapp, here is the full code:
Check the template for the upload form:
@app.route("/upload") def upload(): uploadUri = blobstore.create_upload_url('/submit') return render_template('upload.html', uploadUri=uploadUri)
Put your uploadUri in the form path (html):
<form action="{{ uploadUri }}" method="POST" enctype="multipart/form-data">
Here is the image upload processing function (I am returning blob_key for practical reasons, replacing it with your template):
@app.route("/submit", methods=['POST']) def submit(): if request.method == 'POST': f = request.files['file'] header = f.headers['Content-Type'] parsed_header = parse_options_header(header) blob_key = parsed_header[1]['blob-key'] return blob_key
Now say that you serve your images this way:
/ IMG / ImageFileName
Then your image service function:
@app.route("/img/<bkey>") def img(bkey): blob_info = blobstore.get(bkey) response = make_response(blob_info.open().read()) response.headers['Content-Type'] = blob_info.content_type return response
Finally, in any place where you need to display an image in a template, you simply put the code:
<img src="/img/{{ bkey }} />