2

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!

Mark Skelton
  • 3,663
  • 4
  • 27
  • 47
  • Are you saying it fails on the upload? Or is it failing after the file is uploaded and you somehow try to view it in your browser? If the latter, how are you loading/viewing the file? – Miguel-F Sep 07 '17 at 14:43
  • @Miguel-F The upload works just fine. After it is uploaded and I try to view the PDF in Chrome it fails to load. I am viewing it by going directly to the link for the PDF (i.e. bucket.s3.amazonaws.com/folder/file.pdf) – Mark Skelton Sep 07 '17 at 18:18
  • Since the file seems to be uploading fine and seems to be rendered in other browsers fine, I think this is an Amazon s3 / Chrome issue. If you search Google for "chrome cannot view pdf amazon s3" you will see lots of people talking about the same issue. I think you are correct in that it has to do with the content type being returned. One solution another user came up with is to force the browser to download the file instead of opening inline - https://stackoverflow.com/a/8838357/1636917. You can investigate those other search results for other recommendations. – Miguel-F Sep 08 '17 at 16:41
  • @Miguel-F This isn't a viable solution. As stated, the issue is that Lucee 4.5.5 doesn't apply the correct content type to PDF files. If application/pdf is the content type, it will work in Chrome, and that is what the content type should be anyway. – Mark Skelton Sep 08 '17 at 21:41
  • Since the upload seems to be working you need to show us the code you are using to download/display the PDF instead (not the upload part). We can't help with what you have shared so far. What happens if you manually place a known good PDF file on s3 and then try to view it? – Miguel-F Sep 11 '17 at 11:35
  • @Miguel-F If I place a PDF on s3 using a tool such as Transmit or if I upload using the rest api, or if I upload the PDF using Lucee 5, I am able to view the PDF in Chrome just fine. However, when I upload with Lucee 4.5.5 the PDF will not load in Chome. I am using the same upload code for both Lucee 4 and 5 (see question for upload code). I am viewing the PDF simply by going to the s3 link (i.e. bucket.s3.amazonaws.com/folder/file.pdf). I am not trying to view the PDF using Lucee or anything else, simply accessing it directly from the url. Does that make sense? – Mark Skelton Sep 11 '17 at 11:41
  • Yes that makes sense and is why I tried directing you to a solution that forces the content type from the server's end. Not sure why you think that is not a viable solution. Or perhaps you were referring to forcing a download of the document instead of opening inline. The page that other answer referred to mentioned other response headers you can define besides `response-content-disposition = attachment`. I think you could try setting the `response-content-type = application/pdf` and see if that works. [Amazon s3 doc](http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html) – Miguel-F Sep 11 '17 at 11:56
  • @Miguel-F The reason that is not a viable solution is because that would need to be done for each instance in which cffile is being used to upload files to s3. The viable solution is a patch for Lucee 4.5.5 or something similar that will fix this issue on the server level. The right way to fix this is to fix what is causing the error, in this case, cffile. – Mark Skelton Sep 11 '17 at 12:30
  • Alright, I think that is where we differ. I don't feel like this is a Lucee issue as you do. The same file uploaded works in all other browsers. That leads me to think it is an issue between s3 and Chrome. Otherwise it would not work across the board. Anyway, please be sure to post whatever solution you end up with as it will likely help others. Good luck. – Miguel-F Sep 11 '17 at 12:47
  • @Miguel-F How is it not a Lucee issue? If it wasn't why would it be fixed in version 5? Also, is uploading a PDF with content type "application" correct? No. It should be "application/pdf". – Mark Skelton Sep 11 '17 at 18:52

1 Answers1

0

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