I have few links in my web application , some of them have content type application/pdf and some image/jpeg on click downloads/saves file (respective type)
I have an issue while downloading images, but the following code works perfectly for application/pdf,
I need help in downloading images from URL. I tried changing Content type and response type to image/jpeg but it's not working.
downloadDocFile(fileLocation, fileName) {
var fileNAme = fileName;
var url = fileLocation;
let headerD = this.service.getHeaderDict();
const headerDict = {
'Content-Type': 'application/pdf',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE',
'Access-Control-Allow-Headers': 'Authorization, X-Requested-With, Content-Type, Origin, Accept, X-clientid, X-locale, X-loggedin, X-version',
'Access-Control-Allow-Credentials': true
}
const requestOptions = {
headers: new Headers(headerDict), responseType: ResponseContentType.Blob
};
const proxyurl = "https://cors-anywhere.herokuapp.com/";
this.http.get(proxyurl +url,requestOptions).subscribe(
res => {
const data: Blob = new Blob([res.blob()], { type: 'application/pdf' });
saveAs(data, fileNAme);
})}
service.ts
getHeaderDict(): Object {
return this.headerDict
}