0

I'm uploading a small pdf file to be stored as a blob in the Datastore.

Here's the uploading html, getting the PDF from the user:

<form action="/" method="post" enctype="multipart/form-data">
    <input type="file" name="pdf">
    <input type="submit" value="Upload">
</form>

Here's the handler, storing the PDF to the Datastore:

def post(self):
    p = self.request.POST['pdf']
    if p:
        person.pdf = p.value

Here's the view, showing the user the contents of the PDF:

<embed src="{{ person.pdf }}" width="500"
    height="375" type="application/pdf">

According to all the information I have found, the content of the PDF should reside in p.value. However, the person.pdf attribute is None, and, of course, nothing is displayed.

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
memius
  • 4,045
  • 5
  • 26
  • 25
  • 1
    Have a look at the blobstore for uploading data: https://developers.google.com/appengine/docs/python/blobstore/#Python_Uploading_a_blob – voscausa Dec 04 '13 at 13:21
  • voscausa: are you saying that the datastore has been discontinued? why should i use the blobstore instead? my files are smaller than 1mb. – memius Dec 04 '13 at 14:01

1 Answers1

1

The most basic way that this appears to be wrong is that:

<embed src="{{ person.pdf }}">

should contain the URL to download the pdf file. However, you're uploading a file via your upload form, and presumably storing the file data.

There's at least a few things that can go wrong, you should debug through and at the very least, isolate where something is going wrong:

  1. Are you actually uploading the file?
  2. How is the file encoded as it's uploaded?
  3. How is the file decoded when you get it from the POST data?
  4. How are you storing the actual file in person.pdf?

And finally, are you actually saving person after you modify it? It's generally more helpful to show all your code rather than snippets. And if that's all your code, where on earth is person coming from? It's not actually being initialized anywhere.

dragonx
  • 14,963
  • 27
  • 44