PDF file uploaded to s3 with cffile in Lucee 4.5.5 doesn't display in Chrome

431 views Asked by At

I have a file that uploads a PDF to Amazon s3 using the following ColdFusion code:

<cfif (structKeyExists(form, 'file'))>
    <cffile action="upload" filefield="file" destination="/s3mapping">
</cfif>

<form action="/index.cfml" enctype="multipart/form-data" method="POST">
    <input type="file" name="file">

    <input type="submit">
</form>

If I load the PDF in Chrome is gives me the following error message: "Failed to load PDF document." I tried in other browsers (Firefox, Safari, etc.) and it worked just fine. After doing some investigation I found that Lucee 4.5.5 is not setting the proper content type for PDF documents. Instead of "application/pdf" it simply uses "application". This only is an issue with files uploaded to s3 and furthermore it is only an issue on Lucee 4. Lucee 5 works as I would expect.

Due to the fact that we cannot update our server to Lucee 5 because it is still in beta and causes many of our sites to break, is there a patch for Lucee 4.5.5 that fixes this issue?

Thank you in advance for any help!

1

There are 1 answers

0
Sagar_Dahifale On

Try...this

<cfheader name="Content-Disposition" value="inline;filename=filename.pdf">
<cfcontent file="full specified path of your file" type="extension">

Note: Your path should include s3 secret access key and bucket name