[英]How to correctly send base64 encoded document from express to the client and initiate download?
我有一個包含 3 個應用程序的系統。
后端 flask 應用程序本質上充當所有 API 請求的代理。 客戶端將向后端的端點發送請求,該端點又向快速應用程序發出請求。
express 應用程序生成一個 Word 文檔,如下所示:
// http://localhost:4000/word-export
Packer.toBase64String(doc)
.then(resp => {
const fileContents = Buffer.from(resp, 'base64');
res.send(fileContents);
})
.catch(error => res.send('error'));
我的 Flask 端點邏輯如下所示:
// 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
我需要能夠從客戶端下載此文檔。 我該怎么做,或者我應該如何解碼 base64 字符串? 到目前為止我所嘗試的一切都失敗了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.