Download file with a REST request needing headers and giving the content

后端 未结 4 874
甜味超标
甜味超标 2021-02-06 08:58

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

4条回答
  •  萌比男神i
    2021-02-06 09:47

    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.

提交回复
热议问题