Serving PDF

53 views
Skip to first unread message

Massimiliano Pietroni

unread,
Apr 22, 2012, 9:23:51 AM4/22/12
to google-a...@googlegroups.com
Hi,
I'm developing an app and I have a little problem. I'm storing a PDF in the datastore and then serving it. When I'm serving the file, the one I get is corrupt. By I can't understand why.

I'm storing it like that:
class LogSenderHandler(InboundMailHandler):
 
def receive(self, mail_message):
   
for elemento in mail_message.attachments:
        fax
= FAX()
        fax
.immagine = db.Blob(str(elemento[1]))
        fax
.put()


And I'm serving it like that

class GetImage(webapp.RequestHandler):
 
def get(self):
    immagine
= db.Query(FAX).fetch(limit=1)
   
for elemento in immagine:
     
self.response.headers['Content-Type'] = 'application/pdf'
     
self.response.headers['Content-Disposition'] = 'attachment; filename=fax.pdf'
     
self.response.out.write(elemento.immagine)
      logging
.error(elemento.immagine)

It think everything is okay.

Greg

unread,
Apr 22, 2012, 7:55:51 PM4/22/12
to Google App Engine
On Apr 23, 1:23 am, Massimiliano Pietroni
<massimili...@iviaggidellemeraviglie.com> wrote:
> I'm developing an app and I have a little problem. I'm storing a PDF in the
> datastore and then serving it. When I'm serving the file, the one I get is
> corrupt. By I can't understand why.

I would look very closely at what exactly "corrupt" is. PDFs are very
sensitive to even a single byte being added or removed, so I'd look at
the difference between the original file and the download on a byte
level.

On linux you can use the xxd command, in Windows find a hex dump
utility.
Reply all
Reply to author
Forward
0 new messages