i have some question about file management in ionic. i know in can access the app storage with $cordovafile or with window.requestFileSystem and download resources from the internet, but i cannot access the downloaded resources.
its just a matter of permission?..do i need a routed device?..is possibile to save data OUTSIDE the sandboxed space such as for example the general “download” folder?..
I ‘download’ and access files from the APK using plugins cordova-plugin-file 3.0.0 “File” and cordova-plugin-file-transfer 1.4.0 “File Transfer”.
As far as I can see you should be able to do the same with internet files by just changing the URL. Is the following code to any use to you?
var path = ‘extra/abcd.txt’;
$ionicPlatform.ready(function() {
if (window.cordova) {
var url = cordova.file.applicationDirectory + 'www/' + path;
var targetPath = cordova.file.dataDirectory + path.substring(path.lastIndexOf('/') + 1);
var options = {
encodeURI: false
};
var trustHosts = true;
// Get file from APK
$cordovaFileTransfer.download(url, targetPath, options, trustHosts).then(
function(result) {
$log.log("Successfully got file from APK: " + JSON.stringify(result));
// File saved to data directory, get it.
window.resolveLocalFileSystemURL(result.nativeURL,
function (fileEntry) {
// Create file object
fileEntry.file(function(file) {
$log.log("Got local file");
var reader = new FileReader();
// Callback called when reading file is complete
reader.onloadend = function () {
$log.log("File size: " + reader.result.byteLength);
var fileContent = reader.result;
};
// Read file into an ArrayBuffer
reader.readAsArrayBuffer(file);
},
function() {
$log.log("Failed to get file from data directory");
});
}
);
},
function(error) {
$log.log("Failed to fetch file from APK: " + JSON.stringify(error));
}
);
}
its more or less what i’ve already done, in my specific case i noticed that ive properly downloaded files cannot be opened. i tried two mime types: a png file and an apk file (that is basically the updated apk of my current app),…i also noticed that i cannot access folder or files OUTSIDE the storage space of my app. i’m stucked on this point…