如何使用 webapi Core 在 React 中使用 axios.post 下载文件



我已经使用这个如何使用 webapi 的 axios.post 下载文件(它可能与此重复(来处理这种情况,但我没有得到成功。

 React: 
   axios.post("URL",{data:data, responseType: "blob"})
  1. 作为回应,我得到的是损坏的数据,而不是字节。
  2. 响应类型适用于获取请求,但为什么不适用于帖子?

WebAPI Core: return File(arraybytes, "application/vnd.openxmlformats- officedocument.spreadsheetml.sheet", "test.xlsx");

以下是我如何下载托管在 S3 AWS 存储桶上的视频,

const handleDownload = () => {
    const link = document.createElement("a");
    link.target = "_blank";
    link.download = "YOUR_FILE_NAME"
    axios
      .get(url, {
        responseType: "blob",
      })
      .then((res) => {
        link.href = URL.createObjectURL(
          new Blob([res.data], { type: "video/mp4" })
        );
        link.click();
      });
  };

我使用 onClick 在按钮中触发句柄下载功能。

函数中的网址包含来自 S3 存储桶的视频网址

最新更新