itinance / itinance/react-native-fs

Cannot download file from server with a self signed certificate

Open
#646 5 comments 4 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

**Versions**
```
"react": "16.6.1",
"react-native": "0.57.5",
"react-native-fs": "^2.12.1"
```

**Problem**
I want to download file from the server with a self signed certificate. But I got Java exception:
`Error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.`

**Code**
```
RNFS.downloadFile({
fromUrl: url, // URL to download file from
toFile: path, // Local filesystem path to save the file to
// headers?: Headers; // An object of headers to be passed to the server
background: true, // Continue the download in the background after the app terminates (iOS only)
discretionary: true, // Allow the OS to control the timing and speed of the download to improve perceived performance (iOS only)
cacheable: false, // Whether the download can be stored in the shared NSURLCache (iOS only, defaults to true)
progressDivider: 0,
})
.promise.then(({
jobId, // The download job ID, required if one wishes to cancel the download. See `stopDownload`.
statusCode, // The HTTP status code
bytesWritten // The number of bytes written to the file
}) => {
console.log('bytesWritten ' + bytesWritten + ' of ' + _contentLength);

if(statusCode === 200) {
resolve(path);
} else {
console.log(statusCode);
reject(new Error('Invalid download status code ' + statusCode));
}
})
.catch(err => {
console.log(err);
Sentry.captureException(err);
reject(err);
});
```

I found [this issue](https://github.com/facebook/react-native/issues/20488) and did like [he said](https://github.com/facebook/react-native/issues/20488#issuecomment-409535369) . But still get this error. I assume, that some work should be done inside of `react-native-fs`. I found, that [rn-fetch-blob](https://github.com/joltup/rn-fetch-blob) has `trusty` prop for downloading files from servers with self signed certificates. But I am not Java guy, so I don't know how to implement such prop in the `react-native-fs`. Does `react-native-fs` have this possibillity?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.