'coldfusion cfcontent want to offer open file but not download
In ColdFusion I have code to open or download a file:
<cfif FileExists('#session.exploc#/#attname#')>
<cfset typeatt = FilegetMimeType('#session.exploc#/#attname#')>
<cfheader name = "Content-Disposition" value="attachment;#session.exploc#/#attname#">
<cfcontent type="#typeatt#" file="#session.exploc#/#attname#">
</cfif>
This gives a standard open/download window.
I would prefer a window which just allows the user to open the file, and does not provide a download. Is there a way to do that?
Alternatively, I am happy to open the file in the browser, but since I don't know the filetype in advance I'm not sure how to do that.
Solution 1:[1]
This is not a function of <cfcontent> per-se. All <cfcontent> handles is the MIME-type of the response, the content of it (it can reset it for example), and a few other bits and pieces. It's all about the nature of the content returned by the CFML server.
This is all fairly clear in the docs for <cfcontent>:
Some file types, such as PDF documents, do not use executable code and can display directly in most browsers. To request the browser to display the file directly, use a cfheader tag similar to the following:
<cfheader name="Content-Disposition" value="inline; filename=name.ext">
IE: what you want to be doing is to set the Content-Disposition header with a value of inline to tell the browser to potentially inline the document, if if has the capabilities to do so.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Adam Cameron |
