Skip to main content
RLS
Inspiring
April 1, 2019
Answered

PDF CFCONTENT Display Issue

  • April 1, 2019
  • 4 replies
  • 5521 views

I have a cloud share drive recently assigned to my project, and I was able to copy a number of PDF files into it.   I can use Windows Explorer to navigate to that drive and bring up any PDF file with ease -- double click, view in Acrobat, no problem.

I can use CFDIRECTORY to list the contents of the directory, and I can use FileExists and CFFILE to test and grab a copy of the file, no sweat.

I put a text file in the directory, and I can pull that up with:

<cfheader name="Content-disposition" value="attachment;filename=filenamehere.txt">

<cfcontent reset="true" type="text/plain" file="file:///\\sharedDirectoryHere\filenamehere.txt">

I put a GIF in place and <image> displayed it easily.

I can use the following code pair to view PDF's on another project's share with no issue, PDF pops right up...

<cfheader name="Content-disposition" value="attachment;filename=filenamehere.pdf">

<cfcontent reset="true" type="application/pdf" file="file:///\\otherSharedDirectoryHere\filenamehere.pdf">

... but if I try to read and display a PDF on my shared directory, it tells me the file is missing or corrupt and will not display it.

Your thoughts, please?

    This topic has been closed for replies.
    Correct answer RLS

    Resolution?

    There are two shares in question. It does appear that permissions are the culprit.  A number of groups with permissions were removed and others were aligned properly by assigning the ColdFusion service to the permissions group responsible for the share, and the ability to serve up a PDF now works on one of the two shares.

    The other share is not working, but that is likely due to the permissions being production, not development, and there appears to be no good way to properly and fully test it without migrating through to production and testing it, backing out the change if it does not.

    It would be awesome if someone ever found or developed a tool that would diagnose this type of situation, independent of the language used to develop, kind of like the OBD plug-in for your car.  Did Norton ever make utilities for that? :-)


    Now on to my next problem: getting the .net-friendly/ColdFusion-ignorant (in the true sense of the word) support to understand that the CF Application Server they installed on my machine for development is pretty much worthless without the Administrator password, and it's NOT the Administrator-for-windows password that I'm looking for.  Sigh.  The battle is real.

    Thank you everyone for all your help on this!

    4 replies

    RLS
    RLSAuthorCorrect answer
    Inspiring
    April 29, 2019

    Resolution?

    There are two shares in question. It does appear that permissions are the culprit.  A number of groups with permissions were removed and others were aligned properly by assigning the ColdFusion service to the permissions group responsible for the share, and the ability to serve up a PDF now works on one of the two shares.

    The other share is not working, but that is likely due to the permissions being production, not development, and there appears to be no good way to properly and fully test it without migrating through to production and testing it, backing out the change if it does not.

    It would be awesome if someone ever found or developed a tool that would diagnose this type of situation, independent of the language used to develop, kind of like the OBD plug-in for your car.  Did Norton ever make utilities for that? :-)


    Now on to my next problem: getting the .net-friendly/ColdFusion-ignorant (in the true sense of the word) support to understand that the CF Application Server they installed on my machine for development is pretty much worthless without the Administrator password, and it's NOT the Administrator-for-windows password that I'm looking for.  Sigh.  The battle is real.

    Thank you everyone for all your help on this!

    Community Expert
    April 29, 2019

    If the CF service is running as a user account instead of a security context, it should be very easy to test its access to that share. Just log into the box running CF, open a command prompt as that CF service's user account, and see if you can access the contents of the share from that command prompt. If the CF service isn't running as a user account, but instead is running as a security context (the default behavior for CF and most other Windows services) you should probably change it to a user account but that will be difficult in your production environment without a lot of testing.

    If you need your CF Administrator password from your own local machine, and you have sufficient rights on that machine, you can remove the line in c:\coldfusion2018\cfusion\lib\neo-security.xml that requires the password in the first place. You can then reset the password as you like. This has nothing to do with the CF service user account password, though.

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC
    RLS
    RLSAuthor
    Inspiring
    April 29, 2019

    Thank you, Dave.

    First, to log onto that machine in this company would require an act of God and likely an act of Congress (not entirely kidding given the fact that we're in this permissions situation due to congressional action).  There is no way that is going to happen, much less changing the user account.  If I could do that, if I had that much freedom here, I could have finished this project (4 months now and counting) in the first day (or at least the first week) and been on to something else, saving this company a ton of money.  I was brought in to migrate from CF 8/10 to CF 2016 but in these 4+ months I _might_ have 8 hours -- cumulative -- of CF Programming under my belt, and a lot of that was actually review of legacy code for compliance. Not what I was told I'd be doing.

    For the CF Admin password -- I will remember that!  Well...I'll try to remember that.  That could have solved this problem so much more quickly, although one never knows - they may have some auto-monitoring/psw reset program in place that would have thwarted my efforts because I didn't use official channels.

    Nothing but fun here. Hope you're having a blast where you are! :-)

    Charlie Arehart
    Community Expert
    Community Expert
    April 6, 2019

    These last few replies support what I was getting at in my last one, when I proposed that you try putting the PDF in a web accessible directory, and then try calling it from there.

    Your reply was that you could not do that because it was against your organizational rules, but to be clear *I'm not saying to do it for production purposes. I'm saying to do it for diagnostic purposes*, to understand this problem.

    If you put the PDF in a web accessible directory, even for just a minute, and you call it, what happens in THAT request? And do put it in the same place where the CF page is being called, so that it is governed by the same rules in IIS which would have governed the calling to a CF page trying to serve it up via content. And do be sure also request the PDF via the http:// protocol, not file://, for the same reason.

    If the PDF still cannot be served to your browser, then it would clearly confirm that this problem has nothing to do with ColdFusion, and instead wouldn seem s a problem of IIS serving it. And then, as has been discussed here, you could contemplate various things like is it about permissions, is it about perhaps IIS settings influencing the serving of the PDF, and so on. Heck, it could be a firewall, waf, or antivirus problem.

    And please, before you assert, "this can't be it, because it works if I point to her share instead of mine", could you just try it? There are many things you're saying and not saying that we have to read through from afar. I can think of various ways that you could be doing things, where there's more than is being said. This is why having an online session would be valuable, but I know it's not an option. So please, just try it. :-)

    You're clearly a smart person who is thinking through things very carefully, covering all your bases. But remember the old  adage about a lawyer who represents himself in court. :-) For the sake of all the time you and we have been spending on this, can you please just try it?

    /Charlie (troubleshooter, carehart. org)
    RLS
    RLSAuthor
    Inspiring
    April 10, 2019

    Charlie,

    I'm sorry for such a slow reply! Life got in the way for a few days.

    I copied a PDF directly into the code base, same directory.  Here are my attempts and the results, generified for this response to keep me out of trouble.

    <cfheader name="Content-disposition" value="attachment;filename=filename.pdf">

    <cfcontent reset="true" type="application/pdf" file=file:///\filename.pdf">

    --Received the "damaged file" error message.

    <cfheader name="Content-disposition" value="attachment;filename=filename.pdf">

    <cfcontent reset="true" type="application/pdf" file="filename.pdf">

    --Received the "damaged file" error message.

    https://subdomain.domain/filename.pdf
    --Displayed the PDF directly without issue (it worked).

    <cfheader name="Content-disposition" value="attachment;filename=INS615.pdf">

    <cfcontent reset="true" type="application/pdf" file=https://subdomain.domain/filename.pdf">

    --Asked to download, then showed it without issue (it worked).

    What does that say, then?  IIS is working but the FILE serve has issues, maybe content policy is the problem?

    RLS

    Charlie Arehart
    Community Expert
    Community Expert
    April 4, 2019

    This just doesn't make sense, that cffile and cfcontent would alone react differently in their ability to process a given file/path.

    So when you say, in conclusion, that " it tells me the file is missing or corrupt and will not display it", are you saying you get an error from CF? What is it, exactly?

    Or might the error be coming from your browser, in which case it may not be about cf's inability to access the file after all. Indeed, what happens if you remove the cfheader line?

    /Charlie (troubleshooter, carehart. org)
    RLS
    RLSAuthor
    Inspiring
    April 4, 2019

    I agree. We had a two hour telcon last Friday night with engineers from all over the company, at least a dozen people on at the same time, screen share, things tried, no resolution.  The best guess so far is that it's a rights issue, but that seems odd also.

    To answer your questions, I am NOT getting an error from CF - it comes from Acrobat, I think, the one about the file being corrupt.

    If the error was from my browser, why can I open a PDF on another's file share but not mine?

    Haven't tried removing the CFHEADER line, will give that a shot when I get in.

    RSL

    Charlie Arehart
    Community Expert
    Community Expert
    April 4, 2019

    Ok, this really changes things. It sounded from the outset like you were saying the error was in the cfcontent, and so was a CF error, in which case it begged the question how cffile would work and cfcontent would not--thus my previous questions.

    Now that we know it's on your client end (whether browser, or acrobat, or an acrobat plugin in your browser), that changes where to focus.

    So first, you seem unsure if it IS your browser or acrobat. Please do confirm. Do you at least request the url in a browser?

    And if so, have you viewed the request with the dev tools feature of your browser? (This is available in all browsers. Typically you can right click on whitespace of your page and choose "inspect". Then choose the "network" tab among those shown in the tool.) This would allow you to see the communication to/from the server, in terms of status codes, headers, and content. I suspect the answer could be right there.

    Or more simply, have you tried the request from multiple browsers types, or from different machines?

    BTW, I do those shared desktop sessions myself as consultant, troubleshooting such errors (cf and related) every day. If your urgency warrants that over lots of back and forth here, you can learn more about my services (rates, approach, satisfaction guarantee, and more) at carehart.org/consulting.

    /Charlie (troubleshooter, carehart. org)
    Charlie Arehart
    Community Expert
    Community Expert
    April 1, 2019

    When you say the problem is that you can't "read and display a PDF on my shared directory", how does your code differ from the two working examples you show above?

    /Charlie (troubleshooter, carehart. org)
    RLS
    RLSAuthor
    Inspiring
    April 1, 2019

    Charlie,

    I can read, but it won't display.

    My code is identical save for the path and file name.

    RLS

    Charlie Arehart
    Community Expert
    Community Expert
    April 2, 2019

    Ok, but you had said originally that you COULD use "CFFILE to test and grab a copy of the file", while cfcontent fails.

    Are you saying that the path used in cffile (working) and cfcontent (not working) is identical, or if not, how do they differ?

    /Charlie (troubleshooter, carehart. org)