I currently have an API setup in the following way.
@app.route('/', cors=cors_config, methods=['GET'])
def index():
request = app.current_request
file_name = "orders.csv"
file_path = '/tmp/{}_{}'.format("Life", file_name)
with open(file_path, 'w') as csvFile:
field_names = ["OrderID", "OrderedBy", "Agent"]
writer = csv.DictWriter(csvFile, fieldnames=field_names)
writer.writeheader()
for item in range(10):
writer.writerow(
rowdict={
"OrderID": str(1),
"OrderedBy": "noob",
"Agent": "pro"
}
)
csvFile.close()
with open(file_path, 'rb') as f:
contents = f.read()
f.close()
file_size = os.path.getsize(file_path)
headers = {'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename={}'.format(file_name),
'Content-Length': str(os.path.getsize(file_path))
}
return Response(body=contents, headers=headers)
Now, when running this code using I can download the file which is being created here without issues. However after deploying this to my AWS Account, the API endpoint allows me to download a file but it contains the binary string of the file that I want. I read some other posts which indicated to update the contentHandling path to CONVERT_TO_BINARY (See the answer here) which I did and then redeployed the API from inside API Gateway (not via chalice deploy). It still is showing the same behavior.
Is there any way to solve this?