Prompt file download

前端 未结 5 1873
一生所求
一生所求 2020-12-11 14:39

I have a link on my page on click of which I am trying to generate a PDF document and then show the \"Open - Save\" prompt on the browser.

My HTML (reactjs component

5条回答
  •  孤街浪徒
    2020-12-11 15:16

    Your issue is that the GetMyDocument function will receive the PDF file as a server response, and currently you are doing nothing with that response. You need to handle the response in the then callback. Saving files from javascript is not entirely simple, so I would recommend using an external library such as filesaver.js to help you.

    It will end up looking something like...

    _getMyDocument(e) {
        GetMyDocument(this.props.mydata)
        .then((response)=> {
            const returnedFile = new Blob([response], { type: 'application/pdf'});
            saveAs(returnedFile);
        }).catch(error=> {
    
        });
    

提交回复
热议问题