如何处理前端(reactjs)上的res.download(pathName)

发布于 2025-01-28 18:11:42 字数 139 浏览 2 评论 0原文

我已经在服务器(nodejs)上编写了一个代码,该代码将通过Express Res.Download(Path)向前端发送.CSV文件。我想知道如何使用Fetch API处理响应,这将允许前端下载已发送的文件(.csv)。

我在前端使用ReactJ。

I have written a code on my server(NodeJS) that will send a .csv file to the frontend with express res.download(path). I would like to know how I can handle the response with fetch API that will allow the frontend to download the file(.csv) sent.

I am using reactJs on my frontend.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呆橘 2025-02-04 18:11:42

我能够通过使用 downloadjs 在我的前端

import download from 'downloadjs'
...
//get request
fetch(url).then(res => res.blob())
.then(blob => download(blob, 'name of file', 'data type')) // this line automatically starts a download operation
.catch(err => console.log(err));

我希望您有帮助您

I was able to solve this by using the downloadJs on my frontend

import download from 'downloadjs'
...
//get request
fetch(url).then(res => res.blob())
.then(blob => download(blob, 'name of file', 'data type')) // this line automatically starts a download operation
.catch(err => console.log(err));

I hope this helps you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文