Hi Hope you all are doing well. I am new here in ionic and getting problem while storing and downloading file. I want to download a mp3 file and store in IOS but not able to download. My code is below
` downloding(file, name) {
if (this.platform.is(“cordova”)) {
this.file
.checkDir(this.file.externalRootDirectory, "Downloads")
.then(
// Directory exists, check for file with the same name
(_) =>
this.file
.checkFile(
this.file.externalRootDirectory,
"Downloads/" + name + ".mp3"
)
.then((_) => {
alert("A file with the same name already exists!");
})
// File does not exist yet, we can save normally
.catch((err) =>
this.fileTransfer
.download(
file,
this.file.externalRootDirectory +
"/Downloads/" +
name +
".mp3"
)
.then((entry) => {
alert("File saved in: " + entry.nativeURL);
})
.catch((err) => {
alert("Error saving file: " + err.message);
})
)
)
.catch(
// Directory does not exists, create a new one
(err) =>
this.file
.createDir(this.file.externalRootDirectory, "Downloads", false)
.then((response) => {
alert("New folder created: " + response.fullPath);
this.fileTransfer
.download(
file,
this.file.externalRootDirectory +
"/Downloads/" +
name +
".mp3"
)
.then((entry) => {
alert("File saved in : " + entry.nativeURL);
})
.catch((err) => {
alert("Error saving file: " + JSON.stringify(err.message));
});
})
.catch((err) => {
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>", JSON.stringify(err));
alert(
'It was not possible to create the dir "downloads". Err: ' +
JSON.stringify(err.message)
);
})
);
} else {
// If downloaded by Web Browser
let link = document.createElement("a");
link.download = name + ".mp3";
link.href = file;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
link = null;
}
}`
I tried multiple solution from google but all in vain.My error is
Error Link is here https://prnt.sc/uoo4bx
I am to much depressed. Please help me. i would be really thankful to you for such favour.