I am using AngularJs with a REST API. I don\'t have the hand on the REST API. I can store digital object with the API by sending a REST request. I can get it also with a GET req
Thanks everybody for helping find a solution.
I am not able to find a satisfying solution in javascript and client side application. I am going to make a proxy class communicating with the API.
This will send the REST request with security headers and will give as response the file content.
This class will be called by a HTTP GET request, so the 'save as' process will be managed easily thanks to right response headers.
I think you could using blob, something like
var content=...the content of your request;
var mypdf = new Blob(content, {type : 'application/pdf'});
and check answer from "panzi" in this other question Using HTML5/Javascript to generate and save a file
(One character per element in the array seem pretty nice binary. Probably you don't need to transform it. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data )
you can use this instead of above code :
var url = config.domain + 'file/' + file;
var parameters = "Authorization=" + user.auth +
"&secret-key=" + user.secretkey;
var reportParameters = url + encodeURIComponent(parameters);
window.location.assign(reportParameters);
Maybe you could do something like this?
var a = document.createElement('a');
a.href = 'data:attachment/pdf,' + encodeURI(data);
a.target = '_blank';
a.download = 'filename.pdf';
a.click();
You'd just have to make sure that data
was in the correct format, which IIRC is base64.