Display PDF stream returned from controller using jquery in new window

后端 未结 2 1970
情话喂你
情话喂你 2021-02-06 10:22

I have a controller action which reads a .pdf file from azure blobstorage and returns stream object to the $.ajax() method.

Controller returns<

2条回答
  •  名媛妹妹
    2021-02-06 10:51

    I couldnt find a exact answer to this question. I found a bunch of different questions. I finally was able to piece together by using fetch. You need to accept type 'arraybuffer', then you turn into a blob with resopnse.blob(). Then you can open the blob in a new window.

              fetch('/post/url', {
                            method: 'POST',
                            headers: {
                                Accept: 'arraybuffer',
                                'Content-Type': 'application/json',
                            },
                            //you need to use json here
                            body: JSON.stringify({ items: [{ ItemId: 3, Quantity: 40 }], fileId: 2 });
                        })
                            .then(response => response.blob())
                            .then(data => {
                                var popup = window.open(URL.createObjectURL(data), "height=500,width=750);
    
                       });
    

提交回复
热议问题