REST API: Download File from repository and show in brower

it is actually not a KNIME server problem, but maybe someone can help me.
I use a workflow to save some pdf files in the KNIME repository.
I would like to link these files on another website (access by REST API).
<a href="http://ServerAdress:Port/knime/rest/v4/repository/data/test.pdf:data" target="_blank"> Show PDF xyz </a>
The problem is that the pdf file is downloaded and not displayed in the browser tab.
Can I open the file with HTML / JavaScript in the browser?

Hi @Tim8200 , I think this might be more on the client side (browser) than on the server side. The browser has to be able to open pdf to start with - this is not something that a browser can do by default, you need to install some plugins/extensions (the browser plugins usually get installed when installing a pdf reader).

The next thing to look at is how the browser is configured. For security reasons, the browser might be set to download the pdf file instead of opening it.

Hello @bruno29a,
thank you for quick reply.
But i don’t know how to configure the browser because it works fine with any other link e.g.:

<a href="" target="_blank" >PDF Anzeigen</a>


Hi @Tim8200 , ok, then your browser is already configured.

One thing that I used to do in PHP several years ago was to control the http header on the server that allowed control on whether to download or to open (stream) a file on the client side. I suppose that Knime server should be able to send these http headers as well - would need someone from the Knime team to confirm. The http headers that would usually do it would be:
'Content-Type: application/pdf'
'Content-Disposition: inline; filename="file.pdf"'

The “inline” Disposition as opposed to “attachment” would allow the browser to open the file instead of downloading.

Edit: Any reason why you are appending “:data” at the end of the url?

Hi @bruno29a ,
appending “:data
that’s what it says in the KNIME REST documentation

May be that’s why it “Downloads” it? :slight_smile:

Can you try without the “:data”?

of course I have tried it without the :data :slight_smile:
doesn’t work.
I know that the file is being “downloaded”.
The question was rather how can i open the downloaded file in the browser using html / javascript.
i have found a solution, not very nice but seems to work.

const url2 = 'http://Server:Port/knime/rest/v4/repository/somedata.pdf:data'
var xhr = new XMLHttpRequest();'GET', url2);
xhr.responseType = "blob";
xhr.onload = () => {
	const file = window.URL.createObjectURL(xhr.response);,'_blank')

Hey @Tim8200 , I think your solution is nice actually, this javascript is a very good solution.