react-native-blob-util
react-native-blob-util copied to clipboard
IOS download document problem
Hi, I try to download file in ios but I can't see file. in Andriod everthing OK. my versions: "react-native": "^0.68.2", "react-native-blob-util": "^0.16.0",
this my download function
async function handleDownload(val) { try { const fileExtension = val.workorderDocumentUrl.split('.')[1]; const fileName =
/${val.workorderDocumentName}.${fileExtension}`;
const {workorderDocumentGuid, workorderDocumentName} = val;
const configOptions = Platform.select({
ios: {
fileCache: true,
path: ReactNativeBlobUtil.fs.dirs.DocumentDir + fileName,
notification: true,
IOSDownloadTask: true,
},
android: {
fileCache: false,
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
path: ReactNativeBlobUtil.fs.dirs.DownloadDir + fileName,
description: 'Downloading...',
},
},
});
if (Platform.OS === 'ios') {
ReactNativeBlobUtil.config(configOptions)
.fetch(
'GET',
`${store.baseUrl}/docs?guid=${workorderDocumentGuid}`,
{
'accept-version': 'v3',
'inavitas-tenant': store.tenant,
},
)
.progress((received, total) => {
console.log('PROGRESS', received, total);
})
.then(res => {
setTimeout(() => {
var filePath = res.path();
ReactNativeBlobUtil.ios.presentPreview('file://' + filePath);
console.log('RESIOS', res);
//ReactNativeBlobUtil.ios.openDocument(res.data);
}, 300);
// the temp file path
console.log('The file saved to ', res.path());
setSuccessDownload(true);
console.log('DIRS', ReactNativeBlobUtil.fs.dirs);
})
.catch(err => console.log('download Err', err));
} else {
ReactNativeBlobUtil.config(configOptions)
.fetch(
'GET',
`${store.baseUrl}/docs?guid=${workorderDocumentGuid}`,
{
'accept-version': 'v3',
'inavitas-tenant': store.tenant,
},
)
.then(res => {
ReactNativeBlobUtil.android.actionViewIntent(res.path());
// the temp file path
console.log('The file saved to ', res.path());
setSuccessDownload(true);
console.log('DIRS', ReactNativeBlobUtil.fs.dirs);
})
.catch(err => console.log('download Err', err));
}
} catch (err) {
console.log(err);
}
}`
Here is my debug console, I can see directory && process
For iOS, you can use react-native-share
once you download the file to save it to files.
.then((res) => {
// the temp file path
console.log('The file saved to ', res.path());
// in iOS, we want to save our files by opening up the saveToFiles bottom sheet action.
// whereas in android, the download manager is handling the download for us.
if (Platform.OS === 'ios') {
const filePath = res.path();
let options = {
type: 'application/pdf',
url: filePath,
saveToFiles: true,
};
Share.open(options)
.then((resp) => console.log(resp))
.catch((err) => console.log(err));
}
})
On iOS you won't be able to see the files in the Files app unless you share them
For iOS, you can use
react-native-share
once you download the file to save it to files..then((res) => { // the temp file path console.log('The file saved to ', res.path()); // in iOS, we want to save our files by opening up the saveToFiles bottom sheet action. // whereas in android, the download manager is handling the download for us. if (Platform.OS === 'ios') { const filePath = res.path(); let options = { type: 'application/pdf', url: filePath, saveToFiles: true, }; Share.open(options) .then((resp) => console.log(resp)) .catch((err) => console.log(err)); } })
or use this
ReactNativeBlobUtil.ios.previewDocument(file.path());
@Saad-Bashar i had the same problem, appending .pdf
to the path fixes the problem for me
path: ${dirs.DocumentDir}/${fileName}.pdf
,
LOG The file saved to /Users/xx/Library/Developer/CoreSimulator/Devices/FEBCC312-3D3A-4C60-A008-49A488000139/data/Containers/Data/Application/6DE346D7-CC55-4E21-B9F5-1D9766E977EB/Documents/Resources-1701931717558
LOG The file saved to /Users/xx/Library/Developer/CoreSimulator/Devices/FEBCC312-3D3A-4C60-A008-49A488000139/data/Containers/Data/Application/6DE346D7-CC55-4E21-B9F5-1D9766E977EB/Documents/Resources-1701931752795.pdf
Is there an update on this? I tried downloading the file xlsx in iOS, but it always returns the path simulator.
Is there an update on this? I tried downloading the file xlsx in iOS, but it always returns the path simulator.
I don't know if this is the right solution, but I managed to solve the problem using react-native-share
Share.open({ url: urlPath, saveToFiles: true, }) urlPath is url returned by ReactNativeBlobUtil
Is there an update on this? I tried downloading the file xlsx in iOS, but it always returns the path simulator.
I don't know if this is the right solution, but I managed to solve the problem using react-native-share
Share.open({ url: urlPath, saveToFiles: true, }) urlPath is url returned by ReactNativeBlobUtil
Thank you for your response,
I fixed the issue in iOS. I'm not sure why it didn't download, but I am using the react native file viewer to open it and it's working. The user will need to download a manual.
For iOS, you can use
react-native-share
once you download the file to save it to files..then((res) => { // the temp file path console.log('The file saved to ', res.path()); // in iOS, we want to save our files by opening up the saveToFiles bottom sheet action. // whereas in android, the download manager is handling the download for us. if (Platform.OS === 'ios') { const filePath = res.path(); let options = { type: 'application/pdf', url: filePath, saveToFiles: true, }; Share.open(options) .then((resp) => console.log(resp)) .catch((err) => console.log(err)); } })
The only way I've made it worked was using this approach.
For iOS, you can use
react-native-share
once you download the file to save it to files..then((res) => { // the temp file path console.log('The file saved to ', res.path()); // in iOS, we want to save our files by opening up the saveToFiles bottom sheet action. // whereas in android, the download manager is handling the download for us. if (Platform.OS === 'ios') { const filePath = res.path(); let options = { type: 'application/pdf', url: filePath, saveToFiles: true, }; Share.open(options) .then((resp) => console.log(resp)) .catch((err) => console.log(err)); } })
or use this
ReactNativeBlobUtil.ios.previewDocument(file.path());
I've tried this too but it didn't work for me. Thank you @Saad-Bashar !