0👍
The reason is because downloading file required File system access, which is stricter in Mobile app than desktop. So simple download attribute is not working.
You need to install cordova-plugin-file
: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/
You can follow the tutorial there. Below is my example code if it helps:
saveBlobToSystem(filename, blob) {
// define the folder you want to save first, for example this is download folder in Android
let folderpath = "file:///storage/emulated/0/download/";
let vm = this;
const onError = function(msg) {
console.log("Error saving File to System");
};
window.resolveLocalFileSystemURL(folderpath, function(dir) {
console.log("Access to the directory granted succesfully");
dir.getFile(filename, { create: true }, function(file) {
console.log("File created succesfully.");
file.createWriter(function(fileWriter) {
console.log("Writing content to file");
fileWriter.write(blob);
console.log("Successfully write file to system");
}, onError);
}, onError);
}, onError);
}
However, this cordova plugins may not work on web version, so i think you still need to keep your old code. You can write a simple js function to detect user platform ( web or android app ) and run the corresponding function.
Source:stackexchange.com