itinance / itinance/react-native-fs

getting issue in download pdf , only with those names 4.pdf, form_onboarding_form.pdf

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

Description

import RNFS from 'react-native-fs'; (@2.20.0)

const downloadDocument = async () => {
setPercentage(0);
const timeStamp = new Date().getTime();
const regex = new RegExp(
`^${fileName.split('.')[0]}(?:\\((\\d+)\\))?\\.${
fileName.split('.')[1]
}$`,
);

let basePath = EMPTY_STRING;
let filePath = EMPTY_STRING;
let existingFiles: any = [];

if (Platform.OS === 'ios') {
basePath = `${RNFS.DocumentDirectoryPath}/${fileName.split('.')[0]}`;
} else {
basePath = `${RNFS.DownloadDirectoryPath}/${fileName.split('.')[0]}`;
}

try {
existingFiles = await RNFS.readDir(
Platform.OS === 'ios'
? RNFS.DocumentDirectoryPath
: RNFS.DownloadDirectoryPath,
);
} catch (error) {
console.error('Error reading directory:', error);
}

const matchingFiles = existingFiles
.filter((file: any) => regex.test(file.name)) // Filter files that match the regex
.map((file: any) => file.name);

if (matchingFiles.length > 0) {
filePath = `${basePath}(${matchingFiles.length}).${content_type}`;
} else {
filePath = `${basePath}.${content_type}`;
}

await RNFS.downloadFile({
begin: downloadFileBegin,
progress: downloadFileProgress,
fromUrl: `https://${authDetails.account_domain}.${Config.DOMAIN}/dms/display/?id=${document_id}&resolution=&is_download=true`,
toFile: removePathSpaces(filePath),
headers: {cookie: `whs_id=${whsId}`},
})
.promise.then(r => {
console.log(
'promise result:',
r,
`${RNFS.DownloadDirectoryPath}/${fileName}-${timeStamp}.${content_type}`,
);
})
.catch(error => {
console.log(
'promise result: error',
error,
`${RNFS.DownloadDirectoryPath}/${fileName}.${content_type}`,
);
});
};

Error:
promise result: error Error: ENOENT: no such file or directory, open '/storage/emulated/0/Download/4.pdf' /storage/emulated/0/Download/4.pdf.pdf
TaskDetail.js:178

Note:

I have conformed that issue is not belongs to document. getting issue only on those names.

4.pdf -> getting error
1.pdf -> success
4 .pdf -> success
form_onboarding_form.pdf-> getting error
gorm_onboarding_form.pdf-> success

4.png -> success

can any one help me out please?

[final_onboarding_form.pdf](https://github.com/user-attachments/files/20574439/final_onboarding_form.pdf)

[4.pdf](https://github.com/user-attachments/files/20574480/4.pdf)

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.