1

Is there a reliable way to create a file (specifically via Print.printToFileAsync API), and since it creates the new file in the user's cacheDirectory, copy it across to their documentDirectory - that works in both Android and iOS?

I've come across others trying to do the same thing here, but to no avail.

One solution I've seen is to use the MediaLibrary API to download the file to the device's CameraRoll - but this is hacky and doesn't work on iPhone since the file I'm trying to copy/download is a PDF, and not an image/movie.

Various solutions are listed here too - but they either don't work, or only work in one OS.

My end goal is to be able to generate a PDF on the device and save it to the user's storage, without needing to send information back to the server. My app is not ejected as it stands.

Any advice/direction would be appreciated!

EDIT 1:

Considering ejecting at some stage, but due to the nature of the project I'm working on I'd prefer to do that right at the end. Also came across this post which tries to Share the file URI, but this isn't supported on Android.

jarodsmk
  • 1,876
  • 2
  • 21
  • 40
  • Did you find any solution on this? My requirement is similar, and working on both OS as well. But with Android 11, I am facing issue "Unable to Copy file to Storage". – Surjeet Singh Aug 15 '21 at 11:08
  • @Surjeet unfortunately I left the company and don't have access to that code base anymore - but what I ended up doing was getting the base64 code and converting it to a data URL for the browser to open. Seems really silly, but worked perfectly on both Android and IOS – jarodsmk Aug 17 '21 at 06:30
  • My requirement is to keep it into storage. So converting to base64 and open in a browser won't work. – Surjeet Singh Aug 17 '21 at 06:33
  • Ah that's unfortunate, I don't have a solution for you - humble apologies :( I would have thought since this post was up that Expo would have rectified this issue in some way – jarodsmk Aug 17 '21 at 06:36

1 Answers1

0

I hope you dont have any problem with creating the pdf,to save the file have you tried

https://github.com/Lyrillind/react-native-file-manager

it supports both anroid and ios.

If you want you can build your own native module to save the file ,

http://facebook.github.io/react-native/docs/native-modules-ios.html#content

Srinivasan Sekar
  • 2,049
  • 13
  • 22