I'm trying to make response file download in Odoo 8. The code below worked on Linux. But in Windows OS the file download corrupted.
filecontent = None
with open("C:\\report_media\\output\\" + output, "r") as f:
if f.mode == 'r':
_logger.debug('File object %s', f)
filecontent = f.read()
if not filecontent:
return http.request.not_found()
else:
return http.request.make_response(filecontent,
[("Content-Type", "application/vnd.ms-excel"),
("Content-Disposition", content_disposition(output))])
The file download content looks like this
PK g‘M#ÏÀ _rels/.rels’O‹Â@Å¿J™û
Odoo itself doesn't report any error. Why this is happening? Is there is a fix for this? Also why the zip file header when the file is excel?
PS. I confirm the file path existed, and the file is not zip file, it is an excel file.
This issue happened because different behavior between Python on Windows and Linux. On windows the open file mode should have been rb
not just r
.