SDK Version: 36
Platforms(Android/iOS/web/all): iOS
I want to download from a website some docuements of a private accounts. To download this files i use the redirect link of the accounts private folder. I use this code:
_openLink = (link, name, warn) => {
var offwarn = !this.state.offline && warn;
if (name !== undefined) {
const tmpname = FileSystem.documentDirectory + name.replace("/", "-").replace("^", ".").replace(/\s/g, "");
if (downloads[name] == undefined && !offwarn) {
if (!this.state.offline) {
FileSystem.downloadAsync(link, tmpname).then((value: FileSystem.DownloadResult) => {
console.log(value.headers["Content-Type"])
var extension = value.headers["Content-Type"].split("application/")[1];
var finalname = tmpname + "." + extension;
FileSystem.moveAsync({ from: tmpname, to: finalname }).then(() => {
downloads[name] = finalname;
this._saveDownloads()
this._openLink(link, name, warn)
})
})
} else {
alert("File non scaricato");
}
} else {
const filename: string = downloads[name];
FileSystem.getInfoAsync(filename).then((value: FileSystem.FileInfo) => {
if (value.exists && !offwarn)
this._openPdf(filename, link, false);
else {
delete downloads[name]
this._saveDownloads()
this._openLink(link, name, warn)
}
})
}
} else {
this.changeUrl(link);
this.delLink = true;
}
}
Sample link: https://example.com/private/attachment.php?i=15834&auth=ceckqy9qucsly1tr1hr58fbiso3vlixn
When i tried to download a pdf document from android client its work correctly. Console print as Content-Type “application/pdf”.
When i use this code on ios, with the same link, it doesn’t download the document, but the download page. So the console print as Content-Type html/text.
I think that iOS doesn’t support redirect download link. In fact, I tried to use this code to another website with same redirect download link type and on android I can download my file, but on iOS I download the html page.
Other website tested: https://nextopera.s3.eu-west-3.amazonaws.com
Thank you.