Problem with binary files
See original GitHub issueI’m trying to return an Excel file as an attachment. Here’s my code:
content_type = (
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
response = HttpResponse(content=data, content_type=content_type)
response["Content-Disposition"] = 'attachment; filename="{0}"'.format(filename)
return response
First I had an encoding error:
'utf-8' codec can't decode byte 0xc0 in position 10: invalid start byte: UnicodeDecodeError
Traceback (most recent call last):
File "/opt/apig_wsgi.py", line 44, in handler
return response.as_apig_response()
File "/opt/apig_wsgi.py", line 149, in as_apig_response
response["body"] = self.body.getvalue().decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 10: invalid start byte
So I activated the binary mode:
app = make_lambda_handler(application, binary_support=True)
I have no more errors but my file can’t be read 😦
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Common Problems with Binary Files
Common Problems with Binary Files ... If the data is expected to fall into a known range of values, then a program can...
Read more >A little diddy about binary file formats - BetterExplained
Binary files can get confusing. Problems happen when computers have different ways of reading data. There's something called the “NUXI” or byte-order ...
Read more >Git is Bad at Binary File Management -- But is it Worse than ...
It's no secret that git is terrible at handling binary files out of the box. This can often be addressed with git plugins...
Read more >What is a binary file and how does it work? - TechTarget
A binary file is a file whose content is in a binary format consisting of a series of sequential bytes, each of which...
Read more >Why you should not push binary files to git? And what to do if ...
Don't worry, I'll tell you how to solve this problem? Delete files and all of its history in git; Force push to git....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I added a few more words to the documentation to make this easier to discover in the future: 6e18125459fac889ecbf0ca2e48200a8a715577c
Aha 😃