If I remove the pdf file creation from a tempfile wrapper I am able to send a proper file, but when I wrap with tempfile I get this error:
AttributeError: 'bytes' object has no attribute 'read'
I tried to remove the .read() from my filepath but then I get another error regarding trying to read a closed file. Ive looked online at the flask send_file and it appears there is an issue with using send_file on tmp files. Does anyone have a work around? I dont want to create a file then manually remove it once it is sent, id like to keep it as a tempfile
with tempfile.TemporaryFile() as fp:
PDF.dumps(fp, pdf)
return send_file(fp.read(), attachment_filename="invoice"+str(invoice["id"])+".pdf", as_attachment=True)