Comments (16)
It's currently not possible, no.
I plan on implementing a possibility to write / read to / from the Media collections in august. With this change it then should be possible to store files in the common downloads directory too
from react-native-blob-util.
@Kamani Here is the full logic I am using.
from react-native-blob-util.
@Kamani
I was also using import RNFS from'react-native-fs';
so in my path I just used
path : RNFS.ExternalDirectoryPath +'/certificate.pdf',
from react-native-blob-util.
@arunim2405
I tried to save file directly as you mentioned path : RNFS.ExternalDirectoryPath +'/certificate.pdf',.`
ReactNativeBlobUtil.config({path: RNFS.ExternalDirectoryPath + 'receipt.pdf', addAndroidDownloads: { useDownloadManager: true, notification: true, mime: 'application/pdf', description: 'Downloading Receipt.', mediaScannable: true, }, overwrite: false, })`
But it keeps saving file in /data/data/com.android.providers.downloads/cache/
Any Idea?
You seem to have missed '/' in '/receipt.pdf'
from react-native-blob-util.
@arunim2405 Found issue. I have given path before addAndroidDownloads.
While to make it work need to give path inside addAndroidDownloads.
Thank you so much man.
Infact I think we should atleast update this document.
Because in document https://github.com/RonRadtke/react-native-blob-util#download-example-fetch-files-that-need-authorization-token as well they mentioned to give path directly and not inside addAndroidDownloads.
@RonRadtke I think this should be updated in document.
from react-native-blob-util.
@RonRadtke Infact document contains many links which are resolving to 404. That should be also removed. If document will be clear I do think lot's of developer's will find it helpful.
from react-native-blob-util.
To which directory are you saving the file?
Looks like it is outside of your apps private directories
from react-native-blob-util.
I was trying to download the file in the common downloads directory of android, but I changed that to my app directory and that fixed the issue. Is it or when will it be possible to directly download to the common downloads directory?
from react-native-blob-util.
@arunim2405 how you saved file to your app directory?
from react-native-blob-util.
@arunim2405
I tried to save file directly as you mentioned path : RNFS.ExternalDirectoryPath +'/certificate.pdf',.
`
ReactNativeBlobUtil.config({
path: RNFS.ExternalDirectoryPath + 'receipt.pdf',
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
mime: 'application/pdf',
description: 'Downloading Receipt.',
mediaScannable: true,
},
overwrite: false,
})`
But it keeps saving file in /data/data/com.android.providers.downloads/cache/
Any Idea?
from react-native-blob-util.
@arunim2405 Infact I am also not able to copy file from this directory.
/data/data/com.android.providers.downloads/cache/
Even though I have permission keep failing.
Any solution how you have downloaded file to any other directory?
from react-native-blob-util.
@arunim2405 I am sorry man but honestly I tried that as well not working.
I am not sure how it's working for you.
Are you using Expo? I am not using it.
Is there any way you can show some demo? Honestly I really appreciate your help.
I have also taken access rights before. But it keeps downloading in default directory.
from react-native-blob-util.
@RonRadtke
I think you can breakdown this feature and it will be really helpful.
First supporting for only downlod or upload from default download directory. This will be really good enhancement.
from react-native-blob-util.
ReactNativeBlobUtil.config({
addAndroidDownloads : {
useDownloadManager : true, // <-- this is the only thing required
notification : true,
path : RNFS.ExternalDirectoryPath +'/certificate.pdf',
// Optional, override notification setting (default to true)
//fileCache : false,
title : 'Cowin Certificate downloaded',
mediaScannable : true,
// Optional, but recommended since android DownloadManager will fail when
// the url does not contains a file extension, by default the mime type will be text/plain
mime : "application/pdf",
description : 'Cowin Certificate.'
}
})
.fetch('GET', `https://cdn-api.co-vin.in/api/v2/registration/certificate/public/download?beneficiary_reference_id=${this.state.beneficiary}`,{
Accept: 'application/json',
"Authorization":`Bearer ${token}`,
'Content-Type': 'application/json',
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
})
.then((resp) => {
// the path of downloaded file
console.log(resp.path())
android.actionViewIntent(resp.path(), 'application/pdf')
AlertClass.showAlert(
"CASAMED",
"Your certificate was downloaded. Check out our app more for access to customised physiotherapy plans.",
[
{
text: "Go to Home",
onPress: () => {
this.props.navigation.navigate("HomeScreen");
},
},
{
text: "Download another Certificate",
onPress: () => {
// this.props.navigation.navigate("MyExcercise", { item, selectedDate });
},
style: "cancel",
},
]
);
console.log(resp)
}).catch(e=>{
console.log(e)
})
from react-native-blob-util.
The documentation for sure could use a clean up. You're right about that.
The link you posted is not linking to the correct url.
And it is correct that the path is outside in this example.
Have a look at this part: https://github.com/RonRadtke/react-native-blob-util#android-media-scanner-and-download-manager-support
The outer path is only used if you don't use the addAndroidDownloads, if you're using the DonwnloadManager you need to specify the path within the addAndroidDownloads section.
from react-native-blob-util.
@RonRadtke I'm seeing this issue in "react-native-blob-util": "0.19.4"
Tried different dirs (DownloadDir
, DocumentDir
, CacheDir
) but getting the same error.
WARN Possible Unhandled Promise Rejection (id: 10):
Error: Failed to find configured root that contains /data/data/com.android.providers.downloads/cache/sample-18.pdf
My config:
const fileName = `Resources-${Date.now()}.pdf`;
const dirs = ReactNativeBlobUtil.fs.dirs;
ReactNativeBlobUtil.config({
fileCache: true,
appendExt: 'pdf',
path: `${dirs.DocumentDir}/${fileName}`,
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
title: fileName,
description: 'File downloaded by download manager.',
mime: 'application/pdf',
mediaScannable: true,
},
})
.fetch('GET', url)
.then(async (res) => {
console.log(res.path());
setLoading(false);
if (Platform.OS === 'ios') {
ReactNativeBlobUtil.ios.previewDocument(res.path()); // this is working
} else {
// this is not working
ReactNativeBlobUtil.android.actionViewIntent(
res.path(),
'application/pdf',
);
}
})
.catch((err) => {
setLoading(false);
console.log(err);
});
from react-native-blob-util.
Related Issues (20)
- Android Download Manager notification only shows up at the end
- response.json() is throwing an Error in Android saying No such file or directory HOT 1
- dest.exists() check fails in writeStream() in files of type content:// HOT 1
- Using writeStream() with content:// Uris HOT 1
- File gets corrupted with readStream() with base64 when using bufferSize defaults
- java to kotlin change example HOT 5
- pathForAppGroup typescript error HOT 1
- Error opening APK file: installation package is corrupt HOT 3
- Integration network debugging react-native-debugger HOT 1
- Crash when readStream on IOS
- Problem with java.lang.RuntimeException: java.lang.IllegalStateException: Use of own trust manager but none defined HOT 1
- wifiOnly option doesn't work on iOS as expected
- copyToMediaStore does not work on Android versions lower than 10 HOT 2
- Upload Video [Error: The operation couldn’t be completed. Message too long] HOT 1
- [Error: Unexpected FileStorage response file: null] on android 14 HOT 1
- Run error in windows, due to the WindowsTargetPlatformMinVersion
- ReactNativeBlobUtil.fs does not work if path contains 'content://' HOT 1
- How to get access to assets file (issue opened after trouble shooting read). HOT 1
- Android 14 PDF Issues
- Cancel Download function not working HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-blob-util.