Last active
January 3, 2020 15:46
-
-
Save JamoCA/52c17718ab6a4e047994c6bf3f7dd1f4 to your computer and use it in GitHub Desktop.
Since upgrading to ColdFusion 2016, downloads that are aborted or timed-out now throw a CF error. Here's some sample code on how to prevent it using try/catch.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- 20200103 | |
Since upgrading some applications to ColdFusion 2016, downloads that are aborted or timed-out now throw a CF error. | |
Here's some sample code on how to prevent it using try/catch. | |
https://gist.github.com/JamoCA/52c17718ab6a4e047994c6bf3f7dd1f4 | |
https://dev.to/gamesover/using-try-catch-to-suppress-aborted-download-errors-3j42 | |
---> | |
<cfset FileData = { | |
"name" = "Filename with Spaces.pdf", | |
"path" = "c:\files\File12345.pdf" | |
}> | |
<!--- increase timeout as request will take longer as user may have to specify download location ---> | |
<cfsetting requesttimeout="1200"> | |
<!--- Use double quotes for filename in case it contains spaces ---> | |
<cfheader name="Content-disposition" value="attachment; filename=""#FileData.Name#"""> | |
<cftry> | |
<!--- Use "application/unknown" instead of file-related mime type in order to force download ---> | |
<!--- Use "deletefile" flag to be safe (Past bug: CFMailParam defaults to "no", but still deleted the file.) ---> | |
<cfcontent type="application/unknown" file="#FileData.Path#" deletefile="No"> | |
<cfcatch> | |
<!--- log failure; optional; it's good to have this data in case there's a pattern of failure ---> | |
<cflog file="aborteddownloads" type="information" application="yes" text="#CGI.Remote_Addr#|#FileData.Path#|#CGI.HTTP_User_Agent#|#cfcatch.message#"> | |
Download Aborted | |
<cfabort> | |
</cfcatch> | |
</cftry> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment