Hey, I've been struggling in the last couple of hours trying to solve this but I just can't.
So, I'm generating a vcf file (VCard) and saving it on DocumentDirectoryPath (so far so good),
then I save the file path: (Example: /data/user/0/com.appName/files/Test-ABC.vcf.
Now, I want to be able to download this file, but it keeps giving me this errors.
On Android:
Error: no protocol: /data/user/0/com.appName/files/Test-ABC.vcf
at createErrorFromErrorData (NativeModules.js:116)
at NativeModules.js:79
at MessageQueue.__invokeCallback (MessageQueue.js:288)
at MessageQueue.js:127
at guard (MessageQueue.js:46)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
at debuggerWorker.js:71
On iOS:
Error: unsupported URL
at createErrorFromErrorData (NativeModules.js:116)
at NativeModules.js:79
at MessageQueue.__invokeCallback (MessageQueue.js:288)
at MessageQueue.js:127
at guard (MessageQueue.js:46)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
at debuggerWorker.js:71
ExceptionsManager.js:71 RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL)
My code:
const downloadDest = `${RNFS.DocumentDirectoryPath}/${props.shareOptions.filename}.vcf`;
RNFS.downloadFile({ fromUrl: props.shareOptions.url, toFile: downloadDest, headers })
.promise.then(res => {
// it does not enter here
RNFetchBlob.fs.scanFile([ { path : downloadDest, mime : 'text/vcard' } ])
.then(() => {
console.log("scan file success")
})
.catch((err) => {
console.log("scan file error")
})
return RNFS.readFile(downloadDest, 'utf8');
}).then(content => {
const headers = JSON.parse(content);
console.log(headers);
}).catch(err => console.log(err));
Any help would be really appreciated. Thanks in advance
Are you sure that this happens with "RNFS.downloadFile" and not with "RNFetchblob.fs.scanfile"?
I would suggest to console.log the input parameters as well
@itinance yes, as the the comment on the above code says , it does not even enter there. Plus I tried without the scan file.
Could it be permissions missing? Would that be the shown messages? Didn't find any permissions on the docs
Which version are you using? The explicit ".promise"-Property is not necessary anymore and would fail with new releaseses?
"dependencies": {
"react": "~15.4.1",
"react-native": "0.42.0",
"react-native-fs": "^2.3.2"
}"
The error still persists if I remove the promise and then / catch.
RNFS.downloadFile({ fromUrl: props.shareOptions.url, toFile: downloadDest, headers })
Would you give me an example how to implement the "then" after downloadFile without the promise?
I wonder why does the ExceptionsManager.js:71 RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL) is only triggered on iOS?
@RUIFERNANDE5 Did you ever find a solution to this? I am experiencing this too, but I'm not sure where I'm even using native modules.
encodeURI(`file://${RNFS.DocumentDirectoryPath}/my-download.pdf`)
Most helpful comment
@RUIFERNANDE5 Did you ever find a solution to this? I am experiencing this too, but I'm not sure where I'm even using native modules.