通过lambda和API网关从S3下载PDF在Postman上工作,但在Nodejs Axios中失败,带有Chrome错误 - 失败 - 网络错误

发布于 2025-02-06 12:55:06 字数 1092 浏览 2 评论 0原文

我可以成功地通过lambda和api网关从S3下载PDF。

但是,我使用了建议的Nodejs -Axios。它因“失败 - 网络错误”而失败。

  const downloadSearchResult = async (params) => {
    console.log("download")
    const link = document.createElement("a");
    var axios = require('axios');

    var config = {
      method: 'get',
      url: `https://xxxxxxx.amazonaws.com/v1/xxx?file=${params.row.Filename}`,
      headers: { 
      }
    };
    
    axios(config)
    .then(function (response) {
      link.href = `data:application/pdf;base64,` + response.data;
      link.download = params.row.Filename;
      link.click();
      console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
      console.log(error);
    });
  }

chrome显示了json.stringify(wendesp.data),但文件无法保存。

< < < a href =“ https://i.sstatic.net/m583w.jpg” rel =“ nofollow noreferrer”>报道的chrome失败 - 网络错误

I can download a pdf from S3 via Lambda and API Gateway successfully.

However, I used suggested NodeJs - Axios. It failed with "Failed - Network error".

  const downloadSearchResult = async (params) => {
    console.log("download")
    const link = document.createElement("a");
    var axios = require('axios');

    var config = {
      method: 'get',
      url: `https://xxxxxxx.amazonaws.com/v1/xxx?file=${params.row.Filename}`,
      headers: { 
      }
    };
    
    axios(config)
    .then(function (response) {
      link.href = `data:application/pdf;base64,` + response.data;
      link.download = params.row.Filename;
      link.click();
      console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
      console.log(error);
    });
  }

Chrome showed the JSON.stringify(response.data) but the file won't save.

Chrome reported Failed - Network error

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文