Force file link to open as a preview in [new] tab (instead of downloading)

12

2

Sometimes you want to follow a pdf/image/etc link and actually see it in the browser instead of downloading it.
In my most recent run-in it was with a screenshot on a Mantis server I'm using.

When I click to follow the link it immediately prompts me to save the file, with no option to open it the browser.
I really don't want to download it, open it in an image viewer, then remember to delete the file when I'm done. I'd like that to be handled by the browser when I close the tab for normal images/pdfs like when you click open [image] in new tab.

I know why the browser is doing it, the content is being served with the HTTP header Content-Disposition:attachment, but I'm sure that there would be an advanced setting, hidden context menu option, or awesome extension that would let you view something that somebody wanted you to actually save.

Does anyone know anything like that?


EDIT

Seems Firefox has an add-on for it, but I can't find a port for Chrome.

Hashbrown

Posted 2013-09-26T05:04:40.573

Reputation: 1 720

@Vasko no it hasn't, those answers are all referring to what the webmaster can do to ensure users with their browsers download a file by default. My question is, as a user with no control over how the content is hosted, how do we enforce the opposite – Hashbrown – 2016-05-03T08:27:49.687

This is the source of the article: https://support.google.com/chrome/answer/1060734 Maybe you had Chrome PDF Viewer and Adobe Reader turned off by default?

– Darius – 2013-09-26T07:02:05.287

well this isn't just about pdf's, and I'm certain Content-Disposition overrides it (which is set by the server, not a user preference) – Hashbrown – 2013-09-26T07:19:56.987

3

Just saw this.. and possibly a duplicate? --> http://superuser.com/questions/199382/make-chrome-always-open-pdfs-itself - (The answer refers to use a 'redirector' Chrome extension (https://chrome.google.com/webstore/detail/redirector/lacckjdlmkdhcacjdodpjokfobckjclh) to remove content-disposition header.

– Darius – 2013-09-26T08:09:34.900

Answers

3

Who defines whether the file will be downloaded or opened is the site developer. Naturally the file is opened in the browser, but if the developer force the HTML header below, will always be downloaded.

There is no way to force. :(

Response.AddHeader("Content-Disposition", "attachment; filename=fileToForceDownload.pdf");
Response.AddHeader("Content-Length", 12345);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytesOfFile);

To open in browser, developer must declare:

Response.AddHeader("Content-Disposition", "inline; filename=fileToOpen.pdf");
Response.ContentType = "application/pdf";

The above was written in C# but its parameters are common to any language sites

Sergio Cabral

Posted 2013-09-26T05:04:40.573

Reputation: 189

Android 4, Ice Cream Sandwich. Example: Content-Disposition: attachment; filename="MyFileName.ZIP"; will not work correctly because of the semicolon at the end. Any tests (and summary) for all Android versions ? Useful: http://stackoverflow.com/questions/6319389/streaming-mime-type-application-pdf-from-asp-app-fails-in-google-chrome Google Chrome v12 release introduced a bug that triggers the problem you describe. You can fix it by sending the Content-Length header https://bugs.chromium.org/p/chromium/issues/detail?id=85549 – Kiquenet – 2017-01-25T15:46:43.260

that's not true at all, even in my question I mention that there is a firefox addon that does work, and Darius had posted a comment that worked for chrome. The question specifically asks for a client solution and even alludes that the server-side correction is already known, but inapplicable in this case, so restating here doesn't help us. (I got an upvote for the question recently and I always go back and check on the answers if you're wondering why this comment came out of nowhere a few years later. I just wanted to let you know why you hadn't got the tick) – Hashbrown – 2019-08-07T05:40:30.767

0

as said by Sergio it is the site developer who defines either the file will get downloaded or opened in browser. If you want to view pdf documents then I suggest to enable the Google Docs Extension which comes with chrome by default. Press the ctrl button while you click the image, it opens the image in new tab. I hope this works for users having this issue.

Grayson

Posted 2013-09-26T05:04:40.573

Reputation: 23

defines, sure, but we're looking for a workaround, which isn't impossible. ctrl+click would only work if the disposition isnt set to attachment, which was specified in the question. (this 'answer' would also have been better suited as a comment) – Hashbrown – 2019-08-07T05:33:29.570

0

Have you tried searching Google for "open PDF in Chrome"?

I had an extension that worked well:

Kami (formerly Notable PDF)
2.0.6344
Document Viewer and Office Tool for your browser

However, I disabled it because PDF will open in Chrome, even without that extension.

I do have:

Office Editing for Docs, Sheets & Slides
109.1486.1491
View and edit Microsoft Word, Excel, and PowerPoint files...

This allows me to open most Office files without having Office (look ma, no Office).

Hope this helps.

Reginald

Posted 2013-09-26T05:04:40.573

Reputation: 47

you want to follow a pdf/image/etc link, this question has nothing to do with pdf's specifically – Hashbrown – 2019-08-07T05:31:18.513