pythonflasksendfilex-sendfile

Python Flask send pdf file using decoded request.content


I'm having great difficulty downloading files from a sharepoint server in my flask application.

I'm making a get request to the sharepoint api to get the file and it looks successful when I print my download object

enter image description here

But I cant figure out how to decode the content and then send for download

I've tried the below

return send_file(BytesIO(download.content), mimetype='application/pdf', as_attachment=True, attachment_filename='test.pdf')

But when i try to open it looks like it hasn't decoded properly

send


Solution

  • If you are using requests module and the shortcut method get to make the get request, just returning the content along with the status_code and headers should do the trick

    return download.content, download.status_code, download.headers.items()