I have stored pdf files uploaded by users in the Datastore, as BlobProperties:
<form action="/" method="post" enctype="multipart/form-data">
<input type="file" name="pdf">
<input type="submit" value="Upload">
</form>
with the following handler:
def post(self):
p = self.request.get('pdf')
if p:
person.pdf = p
I have also tried this version of the last line:
person.pdf = db.Blob(p)
which seems to work the same way. I try to display it thus:
<embed src="{{ person.pdf }}" width="500"
height="375" type="application/pdf">
with this handler:
def get(self,person_id):
person = Person.get_by_id(int(person_id))
self.response.headers['Content-Type']="application/pdf"
template_values = {
'person' : person
}
template = jinja_environment.get_template('person.html')
self.response.out.write(template.render(template_values))
The size of person.pdf indicaties that it does indeed contain the entire pdf content, but in the template, the variable
{{ person.pdf }}
causes the following error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 10: ordinal not in range(128)
so nothing is displayed. As far as I understand, Blobproperties are stored as strings. What am I missing?