D
D
Dmitry Filyushin2019-03-11 13:18:43
Django
Dmitry Filyushin, 2019-03-11 13:18:43

How to type cast in Django/Django-Firebird?

I use the following code to display the blob to the user as a downloadable file:

attachment = DocAttachment.objects.get(pk=id)
    response = HttpResponse(attachment.content, content_type='application/pdf')
    return response

Returns the string in the downloaded file:
I'm trying to save directly through the fdb module:
con = fdb.connect(dsn='database.fdb', user='user', password='password')
    cur = con.cursor()
    cur.execute("select content from doc_attachment where id = 39")
    row = cur.fetchone()
    br = row[0]
    response = HttpResponse(br.read(), content_type='application/pdf')
    return response

In the second case, I have a downloaded pdf file.
In the first case, in debugging, it shows the attachment.content object as bytes, in the second case - BlobReader. Is it possible to cast the attachment.content variable to a BlobReader type?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alternativshik, 2019-03-11
@alternativshik

response = HttpResponse(attachment.content, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="doc_attachment.pdf"'

return response

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question