We have a mobile app developed using Angular 7 & Ionic 4. A while back we conducted a penetration test and, in order to be compliant, we changed the way files are transferred in the app. Instead of getting the file url directly through API, we receive an url of which the content type is application/octet-stream
, and we use the following method to download the file and save it in device storage:
downloadFileTransfer(url, fileName) {
const directoryPath = this.device.platform === 'Android' ? this.file.dataDirectory : this.file.documentsDirectory;
const filePath = directoryPath + fileName;
alert("url:" + url);
alert("filePath:" + filePath);
this.nativeHTTP.downloadFile(encodeURI(url), {}, {}, filePath).then(response => {
this.appService.toastTipSuccess('success: ' + response, false);
alert('response: ' + JSON.stringify(response));
}).catch(err => {
this.appService.toastTip('failure: ' + err, false);
});
}
With this code on a real Android device, I can see the url and filePath being alerted just fine, and the response alert after downloadFile callback can be triggered just fine with response
object containing the actual path where this file is supposed to be saved at. However, after checking the device storage, nothing is actually saved in the device, despite the response callback is triggered successfully.
On a side note, this is the latest attempt after many other alternatives failed: saveAs
, createObjectURL
, fileTransfer.download
. Despite many of those approaches work in web browser, none of which worked in standalone app on real mobile devices.
Any insights or assistance would be greatly appreciated, as this issue has bothered our team for several weeks already.