How to display a PDF file in a new tab

I made the HTML file display (read as utf 8) in a new tab as described by dear Steve-Mcl:
https://flows.nodered.org/flow/db68bd4934cf46f39e6e453a348bc419

But the PDF file can only be downloaded in a new tab (read as buffer).
And how do I make it display too?
Please help me with some advice.

You most likely need to set the content-type header to application/pdf.

Then, it will be up to the browser whether it renders or downloads it.

1 Like

TotallyInformation, Thanks for the idea !

Flow from Steve-Mcl

A message is coming from the node "[get] /files/:fn:"

{
"_msgid": "ff8bc8b8.9f8808",
"payload": {},
"req": {
"_readableState": {
"objectMode": false,
"highWaterMark": 16384,
"buffer": {
"head": null,
"tail": null,
"length": 0
},
"length": 0,
"pipes": ,
"flowing": null,
"ended": true,
"endEmitted": false,
"reading": false,
"constructed": true,
"sync": true,
"needReadable": false,
"emittedReadable": false,
"readableListening": false,
"resumeScheduled": false,
"errorEmitted": false,
"emitClose": true,
"autoDestroy": true,
"destroyed": false,
"errored": null,
"closed": false,
"closeEmitted": false,
"defaultEncoding": "utf8",
"awaitDrainWriters": null,
"multiAwaitDrain": false,
"readingMore": true,
"dataEmitted": false,
"decoder": null,
"encoding": null
},
"_events": {},
"_eventsCount": 1,
"socket": "[internal]",
"httpVersionMajor": 1,
"httpVersionMinor": 1,
"httpVersion": "1.1",
"complete": true,
"rawHeaders": [
"Host",
"192.168.11.123:1882",
"Connection",
"keep-alive",
"Upgrade-Insecure-Requests",
"1",
"User-Agent",
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36",
"Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Referer",
"http://192.168.11.123:1882/ui/",
"Accept-Encoding",
"gzip, deflate",
"Accept-Language",
"ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
"Cookie",
"_authorized=admin; sysmode=router; FKUYKTUMUIWNE=SIHGUZCDNEEBCTHC"
],
"rawTrailers": ,
"aborted": false,
"upgrade": false,
"url": "/files/Test.pdf",
"method": "GET",
"statusCode": null,
"statusMessage": null,
"client": "[internal]",
"_consuming": false,
"_dumped": false,
"baseUrl": "",
"originalUrl": "/files/Test.pdf",
"_parsedUrl": {
"protocol": null,
"slashes": null,
"auth": null,
"host": null,
"port": null,
"hostname": null,
"hash": null,
"search": null,
"query": null,
"pathname": "/files/Test.pdf",
"path": "/files/Test.pdf",
"href": "/files/Test.pdf",
"_raw": "/files/Test.pdf"
},
"params": {
"fn": "Test.pdf"
},
"query": {},
"res": "[internal]",
"body": {},
"_parsedOriginalUrl": {
"protocol": null,
"slashes": null,
"auth": null,
"host": null,
"port": null,
"hostname": null,
"hash": null,
"search": null,
"query": null,
"pathname": "/files/Test.pdf",
"path": "/files/Test.pdf",
"href": "/files/Test.pdf",
"_raw": "/files/Test.pdf"
},
"route": {
"path": "/files/:fn",
"stack": [
{
"name": "cookieParser",
"keys": ,
"regexp": {
"fast_star": false,
"fast_slash": false
},
"method": "get"
},
{
"name": "httpMiddleware",
"keys": ,
"regexp": {
"fast_star": false,
"fast_slash": false
},
"method": "get"
},
{
"name": "corsHandler",
"keys": ,
"regexp": {
"fast_star": false,
"fast_slash": false
},
"method": "get"
},
{
"name": "metricsHandler",
"keys": ,
"regexp": {
"fast_star": false,
"fast_slash": false
},
"method": "get"
},
{
"name": "",
"keys": ,
"regexp": {
"fast_star": false,
"fast_slash": false
},
"method": "get"
},
{
"name": "",
"keys": ,
"regexp": {
"fast_star": false,
"fast_slash": false
},
"method": "get"
}
],
"methods": {
"get": true
}
},
"cookies": {
"_authorized": "admin",
"sysmode": "router",
"FKUYKTUMUIWNE": "SIHGUZCDNEEBCTHC"
},
"signedCookies": {}
},
"res": {}
}

A message is coming from the node.
I replaced it:

"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9"

with this:

application/pdf,text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9
и далее это уходит на узел "http".

But nothing has changed.

How else can I insert Content-Type = "application/pdf" ?

Inserting "application/force-download" also did not result in a download request.

application/pdf in this context is the response header.
Doubleclick the http-response node and set the content-type header to application/pdf.

2 Likes

Thank you very much!
It is also possible programmatically from the function node:

msg.headers = {'Content-Type':'application/pdf'};

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.