react-native-pdf icon indicating copy to clipboard operation
react-native-pdf copied to clipboard

Android: Does not work with any remote URL - Possible unhandled promise rejection (id: 2): Error: /data/user/... open failed: ENOENT (No such file or directory)

Open sobrinho opened this issue 1 year ago • 14 comments

What react-native version are you using? 0.74.1

What react-native-pdf version are you using? 6.7.5

What platform does your issue occur on? (android/ios/both) android

Describe your issue as precisely as possible :

  1. Steps to reproduce the issue or to explain in which case you get the issue
  2. Interesting logs Got this exception no matter what URL is provided either cache enabled or disabled.

Works fine with Blob but not with remote URLs.

Join a screenshot or video of the problem on the simulator or device? Screenshot 2024-06-12 at 11 29 38

Show us the code you are using?

import Pdf from "react-native-pdf";
import { StyleSheet, Dimensions, Text, View } from "react-native";
import { useState } from "react";

const MyWebComponent = () => {
  const [source, setSource] = useState(null);

  const uri = "https://www.clickdimensions.com/links/TestPDFfile.pdf";

  return (
    <View style={styles.container}>
      <Pdf source={{ uri: uri, cache: true }} style={styles.pdf} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'flex-start',
    alignItems: 'center',
    marginTop: 25,
  },

  pdf: {
    flex:1,
    width:Dimensions.get('window').width,
    height:Dimensions.get('window').height,
  }
});

export default MyWebComponent;

sobrinho avatar Jun 12 '24 14:06 sobrinho

Facing Same issue

amjpdevp avatar Jun 13 '24 14:06 amjpdevp

@wonday hints?

sobrinho avatar Jun 18 '24 15:06 sobrinho

Is resolved?

1141389882 avatar Jun 19 '24 06:06 1141389882

trustAllCerts={false} helps but in my opinion it isn't good resolve for our problem.

Marcin-Falkowski avatar Jun 19 '24 12:06 Marcin-Falkowski

There's no issue with the certs on the URLs I'm trying. How this would help?

sobrinho avatar Jun 19 '24 12:06 sobrinho

I'm not 100% sure how this would help because i found this resolve in closed issues. I use amazon url's so i can imagine that the certs aren't 100% correct because i had a problem with that before and it works for me now.

But your link is working for me too with this parameter setted on false. const source = { uri: 'https://www.clickdimensions.com/links/TestPDFfile.pdf', cache: true, } return ( <View style={styles.safeArea}> <Pdf source={source} trustAllCerts={false} style={{flex: 1}} /> </View> ) image

Only difference between our environments is React Native version because i use 0.73.3 so if it still doesn't work, you have to wait for other answers, maybe it is something with new architecture.

Marcin-Falkowski avatar Jun 19 '24 13:06 Marcin-Falkowski

Interesting, I will give it a try, maybe the prop name is misleading to what it's actually doing.

I tried a bunch of different URLs and I'm certain the certs are okay since they work everywhere but this library.

sobrinho avatar Jun 19 '24 13:06 sobrinho

I am also facing the same issue in my app as well. Even it is not working after using trustAllCerts={false} . React Native Version : 0.73.5 Android Version: 12,13

Many clients are impacted due to this in my app. can you please help ??

Abhishektaurus avatar Jun 20 '24 14:06 Abhishektaurus

I resolved it with the props trustAllCerts={false}.

Not sure why.

Jackmekiss avatar Jun 25 '24 08:06 Jackmekiss

I resolved it with the props trustAllCerts={false}.

Not sure why.

I get the same issue. trustAllCerts={false} it fixed. I'm using S3 by AWS

tuxlan avatar Jul 26 '24 22:07 tuxlan

Same thing here, the cert does not have any issue but only works with trustAllCerts={false}.

sobrinho avatar Jul 29 '24 17:07 sobrinho

Same problem solved with trustAllCerts={false}

nathangabriel27 avatar Aug 06 '24 12:08 nathangabriel27

Got the exact same issue and indeed setting the prop trustAllCerts={false} did fix it.

XavegX367 avatar Sep 12 '24 09:09 XavegX367

Even I am facing the same issue. After looking at the _downloadFile function in /node_modules/react-native-pdf/index.js file. It is trying to delete the file from the cache without checking if it actually exists or not. It could be the possible reason for this issue.

Following patch can be helpful.

index 56df005..4e7b881 100644
--- a/node_modules/react-native-pdf/index.js
+++ b/node_modules/react-native-pdf/index.js
@@ -259,7 +259,11 @@ export default class Pdf extends Component {
         }
 
         const tempCacheFile = cacheFile + '.tmp';
-        this._unlinkFile(tempCacheFile);
+        if (ReactNativeBlobUtil.fs.exists(tempCacheFile)) {
+            // if temp file exists, then delete it
+            await this._unlinkFile(tempCacheFile);
+        }
 
         this.lastRNBFTask = ReactNativeBlobUtil.config({
             // response data will be saved to this path if it has access right.

abitling avatar Jul 23 '25 07:07 abitling