{"action":"created","issue":{"url":"https://api.github.com/repos/pallets/flask/issues/2048","repository_url":"https://api.github.com/repos/pallets/flask","labels_url":"https://api.github.com/repos/pallets/flask/issues/2048/labels{/name}","comments_url":"https://api.github.com/repos/pallets/flask/issues/2048/comments","events_url":"https://api.github.com/repos/pallets/flask/issues/2048/events","html_url":"https://github.com/pallets/flask/issues/2048","id":180854436,"number":2048,"title":"Binary file corrupted between the server and the client","user":{"login":"Gallaecio","id":705211,"avatar_url":"https://avatars.githubusercontent.com/u/705211?v=3","gravatar_id":"","url":"https://api.github.com/users/Gallaecio","html_url":"https://github.com/Gallaecio","followers_url":"https://api.github.com/users/Gallaecio/followers","following_url":"https://api.github.com/users/Gallaecio/following{/other_user}","gists_url":"https://api.github.com/users/Gallaecio/gists{/gist_id}","starred_url":"https://api.github.com/users/Gallaecio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gallaecio/subscriptions","organizations_url":"https://api.github.com/users/Gallaecio/orgs","repos_url":"https://api.github.com/users/Gallaecio/repos","events_url":"https://api.github.com/users/Gallaecio/events{/privacy}","received_events_url":"https://api.github.com/users/Gallaecio/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pallets/flask/labels/question","name":"question","color":"f7c6c7"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-10-04T10:14:05Z","updated_at":"2016-10-04T11:13:30Z","closed_at":null,"body":"I am using **Python 3** and the following code:\r\n\r\n    @app.route('/')\r\n    def pdf():\r\n        # [Generate PDF as a byte string]\r\n        with open('file.pdf', 'wb') as f:\r\n            f.write(pdf)\r\n        return send_file(BytesIO(pdf))\r\n\r\nOn the server, a valid PDF file is written. On the client, I get an invalid PDF about twice the expected size.\r\n\r\nit looks like an encoding issue, so I am guessing that the fact that I am using Python 3 may be relevant. The differences between the file saved on the server and the one I get on the client is similar to that of [this StackOverflow question](http://stackoverflow.com/questions/35368352/pdf-response-is-corrupted-in-python-3-but-works-in-python-2), but the poster there was passing the PDF data as a string, whereas in my code `pdf` is made of bytes (Python 3 would not let me write the file otherwise)."},"comment":{"url":"https://api.github.com/repos/pallets/flask/issues/comments/251360157","html_url":"https://github.com/pallets/flask/issues/2048#issuecomment-251360157","issue_url":"https://api.github.com/repos/pallets/flask/issues/2048","id":251360157,"user":{"login":"untitaker","id":837573,"avatar_url":"https://avatars.githubusercontent.com/u/837573?v=3","gravatar_id":"","url":"https://api.github.com/users/untitaker","html_url":"https://github.com/untitaker","followers_url":"https://api.github.com/users/untitaker/followers","following_url":"https://api.github.com/users/untitaker/following{/other_user}","gists_url":"https://api.github.com/users/untitaker/gists{/gist_id}","starred_url":"https://api.github.com/users/untitaker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/untitaker/subscriptions","organizations_url":"https://api.github.com/users/untitaker/orgs","repos_url":"https://api.github.com/users/untitaker/repos","events_url":"https://api.github.com/users/untitaker/events{/privacy}","received_events_url":"https://api.github.com/users/untitaker/received_events","type":"User","site_admin":false},"created_at":"2016-10-04T11:13:30Z","updated_at":"2016-10-04T11:13:30Z","body":"On Tue, Oct 04, 2016 at 03:38:30AM -0700, Gallaecio wrote:\n> If I just return the bytestring, it works for a “wget URL -O file.pdf” call,\n> but since I am not setting the Content-Type header, it does not display\n> correctly in a web browser.\n\nThen set the content-type header. If there is documentation that is omitting\nthat, it is a problem with the docs.\n\n> I don’t\n> think I am writing to the same file twice.\n\nYou have a hardcoded temporary path in your example. You *are* writing to the\nsame file.\n\n> Since returning the bytestring “works” and I am using a REST client\n\nREST-clients are irrelevant to this issue. The fact that using the bytestring\nworks is an indication that it has something to do with the file.\n\n> just twice the size, they are corrupted in a similar fashion to that\n> described in the linked StackOverflow question.\n\nThere is also an answer to the question, which indicates that this is not an\nissue with Flask at all.\n\n> \n> -- \n> You are receiving this because you commented.\n> Reply to this email directly or view it on GitHub:\n> https://github.com/pallets/flask/issues/2048#issuecomment-251354050\n"}}
{"actor":{"display_login":"untitaker"}}