Reputation: 21
We have written code to convert a file from json to excel format and its returning the excel file where as if I try to open the file its corrupted.
We have tried pandas and openpyxl to convert the json. Below is the sample code tried to check whether everything is working fine or not.
from flask import request, send_from_directory
df1 = pd.DataFrame([['a', 'b'], ['c', 'd']], index=['row 1', 'row 2'], columns=['col 1', 'col 2'])
df1.to_excel('/tmp/output.xlsx')
return send_from_directory('/tmp/', 'output' + '.xlsx', as_attachment=True)```
Notes: The code has been deployed using kubernetes, we have copied the generated file from the volume and its looking good, while transferring its getting corrupted. And we have tried different content types as well.
Upvotes: 1
Views: 527
Reputation: 11
I was facing the same issue with PPTX files. Used curl for downloading file, and it worked.
The issue is with windows security.
Go to Downloaded file's properties. There will be unblock checkbox at the end. Check it and Press Ok. Now try to open file again.
You can also check if MD5 of both files match or not.
Upvotes: 1