I’m using PDFKit to generate a PDF in the browser. I’m then posting the PDF to a tornado webserver, which I want to return to the browser as a download. Here is the request handler:
class PDF(RequestHandler):
def post(self):
logger.info("Received PDF.")
self.set_header('Content-Type', 'application/pdf')
self.set_header('Content-Disposition', 'attachment; filename="export.pdf"')
self.write(self.request.body)
logger.info("Returning PDF.")
However, the downloaded PDF appears to be URL-encoded (slashes appear as %2F, etc.). What am I doing wrong here?
The problem was actually a combination of base64 decoding and URL unescaping. The following works now: