如何在从 API 调用收到的反应中打开文件

How to open files in react received from API call

一个 API 调用 returns 可以是文本或 pdf 文件或 doc 的文件。向用户展示这些文档的最佳方式是什么?有没有可以处理多种文件格式(.pdf.text.doc)的 npm 模块?提前致谢

如果您提到的 api 以可下载的形式为您提供文件 link,那么您可以使用 Google 文档的嵌入式查看器 如下使用

<iframe src="https://docs.google.com/gview?url=[path_to_file]embedded=truestyle="width:600px; height:500px;" frameborder="0"/>

path_to_file 替换为您从 api 获得的 link。它支持您在问题中提到的文件格式