react-native - 从 blob react-native (expo) 打开 PDF
问题描述
我是新来的,我正在用 react-native 和 expo 做我的第一个应用程序,我遇到了来自 API 的 PDF 响应问题。
这里的目标是能够调用 API 并接收应用程序/pdf 响应并在您按下按钮时下载它。所有这一切都很顺利,但我无法管理任何方式来解释 pdf 响应并从中做点什么。
我尝试过的一些方法:
- 在 pdfViewer 中解释它
- 使用 Expo FileSystem 下载
- 在新窗口或 web 视图中打开它
- 使用 rn-fetch-blob (不能因为博览会)
- 使用 Print.printToFileAsync
- ...
大多数问题来自这样一个事实,即我需要文件中的 uri 来对其执行任何操作,但看起来我无法从 Blob 创建 url。当我尝试 createObjectURL 时出现此错误
错误:无法为 blob 创建 URL!
// Working API Call
response = await axios.get(apiUri.DownloadDocument +id) this.props.id);
// Blob creation
const file = new Blob(
[response.data],
{type: 'application/pdf'});
// This line throws an error
const fileURL = URL.createObjectURL(file);
WebBrowser.openBrowserAsync(fileURL);
如果我用 POSTMAN 调用 API,他无法预览响应,但我可以下载它,它是 pdf 文件,没有问题。
这个问题可能与那些62387371 59622283 55507959 有关
因为我是新手,所以我可能会以完全错误的方式做这件事。感谢您的时间和专业知识。这是我通过 console.log(response.data) 获得的 API 响应的输出
o << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >>
/FontDescriptor 28 0 R
/CIDToGIDMap /Identity
/W [0 [595 606 629 610 608 389 408 610 315 856 608 276 517 607 629 630 276 693 629 631 631 315 631 496 571 293 742 679 553 679 781 627 598 764 334 545 349 630 630 631 631 358 631 631 631 334 966 631 992 315 587 587 630 681 630 ]
]
>>
endobj
31 0 obj
<< /Length 742 >>
stream
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def
/CMapName /Adobe-Identity-UCS def
/CMapType 2 def
1 begincodespacerange
<0000> <FFFF>
endcodespacerange
2 beginbfrange
<0000> <0000> <0000>
<0001> <0036> [<0054> <0068> <00E9> <00E2> <0074> <0072> <0065> <0020> <004D> <0061> <0069> <0073> <006F> <006E> <0064> <006C> <0043> <0075> <0031> <0035> <002C> <0030> <005F> <0046> <0049> <004E> <0041> <004C> <0056> <004F> <0045> <0050> <0044> <003A> <0063> <0066> <0062> <0067> <0032> <0039> <002D> <0038> <0033> <0036> <002F> <006D> <0037> <0040> <002E> <0076> <0078> <0070> <0042> <0071> ]
endbfrange
endcmap
CMapName currentdict /CMap defineresource pop
end
end
endstream
endobj
7 0 obj
<< /Type /Font
/Subtype /Type0
/BaseFont /DejaVuSans
/Encoding /Identity-H
/DescendantFonts [30 0 R]
/ToUnicode 31 0 R>>
endobj
2 0 obj
<<
/Type /Pages
/Kids
[
5 0 R
]
/Count 1
/ProcSet [/PDF /Text /ImageB /ImageC]
>>
endobj
xref
0 33
0000000000 65535 f
0000000009 00000 n
0000025854 00000 n
0000000157 00000 n
0000000252 00000 n
0000000690 00000 n
0000015892 00000 n
0000005735 00000 n
0000006000 00000 n
0000014618 00000 n
0000015070 00000 n
0000014597 00000 n
0000016033 00000 n
0000016293 00000 n
0000024494 00000 n
0000024924 00000 n
trailer
<<
/Size 33
/Info 1 0 R
/Root 13 0 R
>>
startxref
25952
%%EOF
解决方案
推荐阅读
- python - 如果数据框单元格不包含列表中的单词,则清除它
- amazon-web-services - 如何防止 terraform 询问在 AWS Secrets Manager 上设置的变量的值?
- if-statement - 如何修复这种非法的表达之星?
- typescript - 具有特定编号的函数重载
- java - javax.xml.ws.soap.SOAPFaultException:无法从 SOAP 消息上下文和 javax.xml.stream.XMLStreamException 确定操作名称
- mysql - 如何在使用 mysql npm 的查询中将 *array of objects* 从 MySQL 返回到 Node js 服务器?
- javascript - 如何使用 plotly-js 绘制插值数据
- python - Scrapy - 运行多个 Spider,然后将所有结果链接到脚本中的最后一个 Spider
- python - Azure.functions 中的 flask.request.remote_addr
- c# - 带有结果选择器的扫描运算符