[英]How to save a pdf file to file system (ios/android) with react native which can be accessible outside the app
I am receiving the pdf as base64 encoded string from an api and I want to convert this base64 string to pdf and save it in file system of the device. I am receiving the pdf as base64 encoded string from an api and I want to convert this base64 string to pdf and save it in file system of the device. And this file should be accessible outside the app.这个文件应该可以在应用程序之外访问。
Environment: React Native, Expo环境:React Native,Expo
What it the best library that I can use.我可以使用的最好的库是什么。
Looked at lots of resources online, but confused whether they save in local app storage or outside the app.在线查看了很多资源,但很困惑它们是保存在本地应用程序存储中还是应用程序外部。
If you're using Expo, probably Expo FileSystem.如果您使用的是 Expo,可能是 Expo 文件系统。 Because it's an expo package, it works really well in testing and will be easy to implement to your project.因为它是 expo package,所以它在测试中工作得非常好,并且很容易在您的项目中实施。 Here are the docs .这是文档。
After some research, I found that its easy to work with byte stream instead a base64 string.经过一番研究,我发现它很容易使用字节 stream 而不是 base64 字符串。
And as Finley suggested above, using Expo libraries, Expo File-System, Expo Media-Library, Expo-Sharing can be used together to save the image to device storage which can be accessed from outside app.正如 Finley 上面所建议的,使用 Expo 库、 Expo 文件系统、Expo Media-Library、Expo-Sharing可以一起使用,以将图像保存到可以从外部访问的设备存储中。
In case of IOS, use Expo-Sharing to open sharing options and from there we can save a file to file system.对于 IOS,使用 Expo-Sharing 打开共享选项,然后我们可以将文件保存到文件系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.