5

After uploading a PDF to the Media Archive, I am trying to link to it from a page on a site.

While editing content, I use the hyperlink tool then select the PDF I want to link to via the URL input box.

enter image description here

After saving and publishing the content, clicking the link downloads the PDF and I don't see any apparent way to make this view-able in the browser by using the current Media ID Composite provides. When rendered, we get this:

<a href="/media/64d5b13e-07f2-402f-9b1a-dcfd75d977da/F-KbnQ/CompositeDocumentation.pdf" target="_blank">pdf</a>

Is there a way that I can reference a PDF without using the Media ID and simply use the file name instead?

Here is the Request/Response header info: enter image description here

After reading what Pauli Østerø said, I understand the problem but am still not able to think of a solution.

I can get the PDF to view in the browser by adding ?download=false to the href URL via Developer Tools. But when I try to add ?download=false to the href through Composite, it doesn't take affect and I get the console output: "Resource interpreted as Document but transferred with MIME type application/pdf: "http://c1.wittenauers.com/media/4afb7bc8-f703-469d-a9b2-a524d8f93dcb/ryc7iw/CompositeDocumentation.PDF"."

Here is the network trace that was asked for by Pauli. In the image, I included the bit where I add ?download=false to the URL, in source view, just in case there could be another way to add it.

enter image description here

Edit: URL and headers for the page.

Here is the link to the page that contains the link: http://c1.wittenauers.com/cafe/test

Here is the headers for the page containing the link: enter image description here

bpprox22
  • 95
  • 1
  • 1
  • 8
  • I'm not familiar with Media Archive, but the url is probably returning the pdf as an attachment. Maybe try setting the type attribute in the anchor to application/pdf. i.e. pdf Maybe there is something in the advanced tab? – Amber Dec 29 '15 at 18:53
  • @Amber I tried this and it is still performing a download instead of opening up in the browser. The advanced tab just allows me to give it an ID or a Class for CSS. – bpprox22 Dec 29 '15 at 19:04
  • Based on [this answer](http://stackoverflow.com/a/4853943/1324406), you could try unchecking the "open in new window box" so it will not target a new window. – Amber Dec 29 '15 at 19:14
  • @Amber thanks for the suggestion but it has no affect. The problem seems to be that Composite uses the Media Id in the path for the file. If I could work around the Media Id, I should be okay. – bpprox22 Dec 29 '15 at 19:28
  • @bpprox22 Can you post the Network-trace when you click on the link on the C1-page which you have added ?download=false to through Composite. – Pauli Østerø Jan 14 '16 at 13:20
  • @bpprox22 i need to see the exact url that the browser is requesting, and what headers are returned from the server. Like the first picture you posted :) You're also welcome to head over to https://gitter.im/Orckestra/C1-CMS for a more direct communication, then we can post the solution here when we get it to work. – Pauli Østerø Jan 15 '16 at 08:40
  • @PauliØsterø see the updated question. Hopefully I understood what you were asking for. – bpprox22 Jan 19 '16 at 17:18
  • @bpprox22 When i browse to http://c1.wittenauers.com/cafe/test i don't see any link on the page that has a ?download=false querystring. If i go tou http://c1.wittenauers.com/media/4afb7bc8-f703-469d-a9b2-a524d8f93dcb/ryc7iw/CompositeDocumentation.PDF?download=false in my browser, it shows the PDF without downloading it just fine. – Pauli Østerø Jan 19 '16 at 19:37
  • @PauliØsterø I add the query string to the link via the source editor in Composite. Once the page publishes and I browse to it, it is erasing the ?download=false querystring. And you're correct -- if you add ?download=false to the link, it is viewed in the browser. However, I need it to be viewed in the browser _initially_, but Composite seems to be overwriting it. Any idea why? – bpprox22 Jan 19 '16 at 20:11
  • @bpprox22 could be a v5 issue. The test i made was on a 4.3, and there the querystring is kept just fine. I'll investigate. – Pauli Østerø Jan 20 '16 at 15:21
  • I have same problem with Gmail, that I want only save PDF from mail to computer in Chrome and it open it in web browser and save on computer in background, 2 weeks ago functionality works OK, open was open a save was save functionality, now save is open+save... It looks on bug in Chrome... – Vladimír Oravec Feb 24 '20 at 23:22

2 Answers2

4

From what you're experiencing, it seems to me that Composite have gotten the MIME type of your uploaded file wrong, and is therefor not correctly telling the browser that this file is a pdf, and the browser doesn't know what to do with it.

  1. Try deleting the file and uploading it again.
  2. Try add ?download=false and the end of the href to the file. You prob. need to go into source mode of the content editor.

This is the exact line in the Source Code which is responsible for this behavior, and the logic is as follows

  • If there is no Querystring named download, the attachment is determined by the Mime Type. Only png, gif and jpeg will be shown inline, the rest will be shown as attachment.
  • If there is a Querystring named download with a value of false, it will override the Mime Type check and always force the Content-Disposition to be inline.

I made a quick test here to show that the behaviour is a expected. At least in my Chrome browser in Windows 8

Pauli Østerø
  • 6,878
  • 2
  • 31
  • 48
  • Unfortunately, those methods did not change the issue. Have you ever been able to open a PDF in the browser from a Composite site you've worked on? – bpprox22 Jan 04 '16 at 14:40
  • @bpprox22 i have to admit that i've never experienced the issue that you're describing. I don't know how tech-savvy you are, but would you be able to use Fiddler or Developer Tools in your browser, to see what headers are being sent back and forth when you request the pdf file? You can update your Question with the information. – Pauli Østerø Jan 04 '16 at 14:51
  • I added the header info to my question. Sorry for the delay -- holidays and other projects took priority for a bit. – bpprox22 Jan 12 '16 at 15:24
  • @bpprox22 Thank you. It is indeed C1 which is sending a Content-Dispotition: attachment header which forces your browser to download the file. I'll do a quick search in the source code to see why that is, and get back you you. – Pauli Østerø Jan 12 '16 at 15:29
  • @bpprox22 i've updated my answer, in case you don't get notified – Pauli Østerø Jan 14 '16 at 13:18
  • @PauliØsterø I was just curious, based on your knowledge, if there was yet a way to allow PDF's to open up in browsers by default, rather than defaulting to be downloaded? I will have about 1000 PDF's stored in a C1-CMS site and need customers to open then up from the browser. – klewis May 25 '17 at 20:20
  • @blackhawk im afraid not, that would require a small change to the ShowMedia.ashx-file. Not a big deal, but still something to remember when you upgrade the site not to loose such a customization. – Pauli Østerø May 26 '17 at 13:53
3

Expanding on Pauli's answer, you can add the following snippet to your page template to automatically add the '?download=false' to all pdf links.

$("a").each(function () {
    if (this.href.includes(".pdf")) {
        this.href = this.href + "?download=false";
    }
})
Ryan Zeck
  • 51
  • 4