I'm using api_hour for API web server and trying to response to request with excel file. But it is much more difficult than I thought.
If I use nodejs or django, it is fine and there are many guide for it. But api_hour is not. The following code is mine.
headers = {
'Content-Disposition': 'attachment; filename="excel_file.xlsx"',
'Access-Control-Allow-Headers': 'status,Origin, X-Requested-With, Content-Type, Cookie, Accept, X-PINGOTHER',
'Access-Control-Allow-Methods': '*',
'Accept-Ranges': 'bytes'
}
self.responseHeaders = multidict.MultiDict(headers, )
return Response(content_type='application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet',
status=self.status,
headers=self.responseHeaders,
body=response['excel'])
What I found is that the other frameworks, for example nodejs, django, and ASP.NET Core, respond with file using there own encapsulated functions so do not assign binary data, which is response['excel']
in this code, directly to body.
Is there any way to respond with file ? especially excel ? thanks.