I have a system with 3 applications.
- React client for frontend
- Flask backend for API
- Node application for generating a word document (docx)
The backend flask application essentially acts as a proxy for all API requests. The client will send a request to an end-point in the backend that in turn will make a request to the express app.
The express application generates a Word doc like so:
// http://localhost:4000/word-export
Packer.toBase64String(doc)
.then(resp => {
const fileContents = Buffer.from(resp, 'base64');
res.send(fileContents);
})
.catch(error => res.send('error'));
My Flask endpoint logic looks like:
// http://localhost:5000/api/export
response = requests.get(
'http://localhost:4000/word-export', headers=headers, json=json_data)
response = make_response(response.content)
response.headers.set('Content-Type', 'application/msword')
# response.headers.set('Content-Disposition', 'attachment', filename='doc.docx')
return response
I need to be able to download this document from the client. How can I do this, or how should I decode the base64 string? Everything I have tried so far has failed.