通过React下载时损坏的PDF

发布于 2025-01-31 22:52:56 字数 1710 浏览 2 评论 0 原文

我在Azure Blobstorage上上传了PDF,在下载例程中我遇到了一些问题。
我的应用程序与Springboot一起运行,我使用 outputStream httpservletResponse 提供的在 @restcontroller 中。

在前端,我有一个REAC应用程序,可以接收信息并通过浏览器执行下载。 每次将字节流到前端时,我都会收到一个损坏的文件。当我通过失眠或邮递员执行请求时,它可以正常工作。

我试图将这些文件作为文本进行比较,可以看到它们之间的一些差异。

差异

  • 损坏文件的大小几乎是原始文件的大小的两倍
  • 当我在记事本++上打开文件时,它们似乎在其他编码中
    损坏

    一致的
  • 看起来有些字符不好解释
    损坏

    一致的

我的前端使用 filesaver @2.0.2在磁盘上坚持文件

  const blobParts = [];
  const blobOptions = {
    type: axiosResponse.headers['content-type'],
  };
  blobParts.push(axiosResponse.data);

  const file = new File(
    blobParts,
    axiosResponse.headers['content-disposition'].split('=')[1],
    blobOptions,
  );

 return FileSaver.saveAs(file);

我想知道是否有一种方法可以使ANSI通过该文件进行编码持久过程或是否有办法

I have a pdf uploaded in a Azure Blobstorage and I'm facing some problems during the download routine.
My application runs with springboot and I use an OutputStream provided by a HttpServletResponse in a @RestController method to stream the bytes from the blobstorage to the request.

In the frontend I have a Reac application receiving the information and executing the download through the browser.
Every time I stream the bytes to the frontend I got a corrupted file. It works just fine when I execute a request through Insomnia or Postman.

I tried to compare the files as texts and I could see some differences between them.

Differences

  • The size of the corrupted file is almost double the size of the original
  • When I opened files on Notepad++ they seems to be in a different encoding
    corrupted
    corrupted file
    consistent
    consistent file
  • It looks like there are some characters bad interpreted
    corrupted
    corrupted characters
    consistent
    enter image description here

My frontend uses FileSaver @2.0.2 to persist the file on disk

  const blobParts = [];
  const blobOptions = {
    type: axiosResponse.headers['content-type'],
  };
  blobParts.push(axiosResponse.data);

  const file = new File(
    blobParts,
    axiosResponse.headers['content-disposition'].split('=')[1],
    blobOptions,
  );

 return FileSaver.saveAs(file);

I'm wondering if there's a way of keep the ANSI encoding through the persistence process or if there's is a way

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

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

发布评论

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