Display a PDF downloaded through FileSystem to the documentDirectory

#1

I am trying to figure out a way to do this without ejecting. I’ve tried using a WebView

<WebView source={{uri: "file:///..."}} />

But nothing displays. Are there permissions issues? Is it an IOS simulator problem? Is it not possible? I’m getting no errors from the system. Please let me know your thoughts, I’ve spent hours researching this with no luck. I’m hoping with your expertise we can figure out the best approach.

Thanks so much in advance.

#2

Update: This is working for IOS, but not for android. Does anyone know if this is possible for android? I read that Lollipop+ webviews should support PDFs. Is this an android file access problem? Thanks!

#3

Hi @jogillesp! Where are you storing this file on Android? It could definitely be a permission issue depending on where the file is stored.

#4

I’m using the Expo FileSystem module to download the file. The module provides a constant with the path where it stores the file:

documentDirectory

For android, it contains this value:

/data/user/0/host.exp.exponent/files/ExperienceData/%2540jogillesp%252Foo/ for android.

Here is my webview:

      <WebView
        source={{uri: "file:///data/user/0/host.exp.exponent/files/ExperienceData/%2540jogillesp%252Foo/pdfs/26.pdf"}}
        scalesPageToFit={true}
        javaScriptEnabled={true}
        domStorageEnabled={true}
        decelerationRate="normal"
        automaticallyAdjustContentInsets={true}
        />
#5

It seems file:///data/user/0/host.exp.exponent/files/ExperienceData/%2540jogillesp%252Foo/pdfs/26.pdf
doesn’t actually exist on my Mac. Where is the file being stored, or is it being stored? FileSystem throws no errors, and seems to download fine.

#6

Anyone have any ideas? Thanks

#7

The file exists on your Android device (virtual or physical). There are some tools to inspect the files on Android devices that might let you browse to that path if you have the right permissions. You could also use the FileSystem module to verify the existence of the file (ex: try reading it back). If the WebView won’t display the file and it exists, the error might be related to permissions as suggested above, and you’d have to dive more into Android’s implementation to see what the root cause could be.

closed #8

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.