Reputation: 97
I'm tying to download a file to the folder on my external storage. So, initially there will be no folder & hence, I need to create a folder if its not there and save my file in it.
try {
console.log('Download Started');
var directory = android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();
var file = fs.path.join(directory, "/myfolder/" + this.pdf_url.split("/").pop());
var folder = fs.Folder.fromPath(file).toString();
var url = this.pdf_url;
httpModule.getFile(url, file).then(function(r) {
console.log(r);
}, function(e) {
console.log(e);
});
} catch (error) {
console.log("--error");
console.log(error);
}
Thats all, I'm getting this as OUTPUT
JS: Download Started
JS: --error
JS: Failed to create new java File for path /storage/emulated/0/akavya/2014.pdf
This is my Manifest
file
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
Update i followed this link and on ns preview app its working but not on my app. https://play.nativescript.org/?template=play-js&id=w1YmMo&v=2&_ga=2.97108767.1865896142.1577943252-149906011.1576233431
Upvotes: 1
Views: 917
Reputation: 4152
I faced Similar issue, and i solved it by
const documents = fileSystemModule.knownFolders.documents();
documents._path = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
const folder = documents.getFolder('abcde');
var file = fileSystemModule.path.join(folder._path, this.pdf_url.split("/").pop());
var url = this.pdf_url;
console.log("---folder");
console.log(folder);
console.log(file);
console.log(url);
Upvotes: 1