How to reply a binary file using Jupyter Kernel Gateway

19 views
Skip to first unread message

Eduardo de Castro

unread,
Nov 16, 2018, 9:02:41 AM11/16/18
to Project Jupyter
Hi,

I would like to know
how to reply the content of a binary file using the notebook-http mode from Jupyter Kernel Gateway.

For example, I want to publish a HTTP service that returns the PDF file. In the Python notebook, if I try to use print(content), Python adds a 'b' prefix that breaks the file (a browser can't read)

# GET /pdf

#In Python, I need to read it as binary
with open(fname_pdf, 'rb') as f:
 content
= f.read()

#The problem is here, Python adds 'b' prefix and this can't be processed by the browser.
print(content)

# ResponseInfo GET /pdf
print(json.dumps({
 
'headers' : {
 
'Content-Type' : 'application/pdf'
 
}
 
})
)


Regards,
Eduardo
Reply all
Reply to author
Forward
0 new messages