1 year ago

#71414

test-img

tigrou

Is it possible to download a BLOB after the preview has been opened in a new tab?

I use the below code to download some binary data (a PDF document) and open result in a new tab:

$.ajax({
    url: this.downloadurl,
    xhrFields: {
        responseType: "blob"
    }
})
.done(blob => {
    var url = URL.createObjectURL(blob);

    //open blob in new tab
    window.open(url);
    
    //additionally, download the document
    var a = $("<a>", {
        href: url,
        download: this.filename,
    }).appendTo(document.body);
    a[0].click();
});

It also downloads the document automatically because I found out that it's not possible to download it using the download icon in the preview. Below is the PDF document preview in Chrome. If I click on the download icon:

enter image description here

It will show this :

enter image description here

Is there a way to prevent this? It looks like the URL can only be used once.

javascript

jquery

download

blob

0 Answers

Your Answer

Accepted video resources