Highlighted

cfzip unzip to browser

New Here ,
Feb 07, 2016

Copy link to clipboard

Copied

Is there a way to unzip without writing the PDF file inside the zip to disk but directly to the browser for downloading?

Depending upon what version of CF server you're using, it would be like this.

Say your .zip file is located at C:\userguide.zip, and it contains one PDF file, userguide.pdf.

<cfzip file="C:\userguide.zip" action="list" name="filez" />

<cfzip file="C:\userguide.zip" action="readBinary" entrypath="#filez.name#" variable="thisFile" />

<cfheader name="Content-Disposition" value="inline; filename=#filez.name#" />

<cfheader name="Content-Type" value="application/pdf" />

<cfcontent type="application/pdf" variable="#ToBinary(thisFile)#" reset="true" /><cfabort>

HTH,

^_^

UPDATE:  Very important that the filename of the PDF not contain any spaces, slashes, backslashes, etc.  Replace all of these with underscore, if you must.

UPDATE2:  I should also note that the above should be the only code on the page.  Anything before the above will break the process, and anything after will be ignored.

The CFABORT is if you are redirecting to this page from another, then this will offer the PDF to stream without actually going to the page in the browser - it will offer the file, but appear as if it's running in the background.

Views

335

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

cfzip unzip to browser

New Here ,
Feb 07, 2016

Copy link to clipboard

Copied

Is there a way to unzip without writing the PDF file inside the zip to disk but directly to the browser for downloading?

Depending upon what version of CF server you're using, it would be like this.

Say your .zip file is located at C:\userguide.zip, and it contains one PDF file, userguide.pdf.

<cfzip file="C:\userguide.zip" action="list" name="filez" />

<cfzip file="C:\userguide.zip" action="readBinary" entrypath="#filez.name#" variable="thisFile" />

<cfheader name="Content-Disposition" value="inline; filename=#filez.name#" />

<cfheader name="Content-Type" value="application/pdf" />

<cfcontent type="application/pdf" variable="#ToBinary(thisFile)#" reset="true" /><cfabort>

HTH,

^_^

UPDATE:  Very important that the filename of the PDF not contain any spaces, slashes, backslashes, etc.  Replace all of these with underscore, if you must.

UPDATE2:  I should also note that the above should be the only code on the page.  Anything before the above will break the process, and anything after will be ignored.

The CFABORT is if you are redirecting to this page from another, then this will offer the PDF to stream without actually going to the page in the browser - it will offer the file, but appear as if it's running in the background.

Views

336

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 07, 2016 0
LEGEND ,
Feb 08, 2016

Copy link to clipboard

Copied

Depending upon what version of CF server you're using, it would be like this.

Say your .zip file is located at C:\userguide.zip, and it contains one PDF file, userguide.pdf.

<cfzip file="C:\userguide.zip" action="list" name="filez" />

<cfzip file="C:\userguide.zip" action="readBinary" entrypath="#filez.name#" variable="thisFile" />

<cfheader name="Content-Disposition" value="inline; filename=#filez.name#" />

<cfheader name="Content-Type" value="application/pdf" />

<cfcontent type="application/pdf" variable="#ToBinary(thisFile)#" reset="true" /><cfabort>

HTH,

^_^

UPDATE:  Very important that the filename of the PDF not contain any spaces, slashes, backslashes, etc.  Replace all of these with underscore, if you must.

UPDATE2:  I should also note that the above should be the only code on the page.  Anything before the above will break the process, and anything after will be ignored.

The CFABORT is if you are redirecting to this page from another, then this will offer the PDF to stream without actually going to the page in the browser - it will offer the file, but appear as if it's running in the background.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 08, 2016 1
New Here ,
Feb 14, 2016

Copy link to clipboard

Copied

Thank you, that worked perfectly!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 14, 2016 0
LEGEND ,
Feb 16, 2016

Copy link to clipboard

Copied

Glad you got it working, and thank you for marking my answer correct.

V/r,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 16, 2016 0