20 Replies Latest reply on Dec 27, 2006 1:45 PM by BKBK

    CFFILE Rename/Move Error?  Glitch?

    insuractive Level 3
      I have an application that needs that processes a file and needs to rename the file when it finishes processing. I keep getting an (apparently common) error stating:

      Attribute validation error for tag CFFILE.
      The value of the attribute source, which is currently "C:\Program Files\cigna\excel2querytest.xls", is invalid.

      I've noticed the same thing that many people who have posted about this error have: sometimes the process flows through without any errors. The error occurs whether the source/destination is hard coded or is stored in variables. The error occurs whether I use action="RENAME" or action="MOVE". A test using FileExists() always returns true. Before I execute the code I always make sure that the original file exists, and the destination file does not.

      Does anyone know what is causing this problem and if there is a work-around? It seems like this is a pretty nasty bug in CF that a fair number of people have come across (FYI I'm using CFMX7).

      Any help would be greatly appreciated.

      Thanks!

        • 1. Re: CFFILE Rename/Move Error?  Glitch?
          DJ_Jamba
          2 possibles you can test:

          1. space in the path - try the same code but using a path without spaces
          2. permissions - try mode="777"

          <cffile action="RENAME" source="#sServerPathFull#" destination="#sNewFile#" mode="777" attributes="Normal">
          • 2. Re: CFFILE Rename/Move Error?  Glitch?
            MikerRoo Level 1
            I notice you are working with excel files. Excel does not play nice with file locks and sharing.

            If excel is open or has just shutdown, it will lock the file and you can't rename it.

            Wait about 1500 milliseconds and/or use Java to check for a file lock before trying to rename the file.

            Also, file a bug report because the cffile error message is worse than useless, it's misleading!

            • 3. CFFILE Rename/Move Error?  Glitch?
              BKBK Adobe Community Professional & MVP
              Place the following tag at the top to remind Coldfusion about the XLS extension

              <cfcontent type="application/vnd.ms-excel">






              • 4. Re: CFFILE Rename/Move Error?  Glitch?
                Level 7
                > Place the following tag at the top to remind Coldfusion about the XSL extension
                > <cfcontent type="application/vnd.ms-excel">

                All that does is insert an HTTP header in the response, telling the client
                browser how to handle the data. It has no bearing on anything the CF
                server does, internally.

                --
                Adam
                • 5. Re: CFFILE Rename/Move Error?  Glitch?
                  Level 7
                  Can you do a <cffile action="WRITE"> to the destination path? Don't
                  believe the cause of the error when CF reports errors with <cffile>: it
                  gets confused easily.

                  Not that it's any help, or tells us much, but you code works fine for me
                  (same path).

                  --
                  AAdam
                  • 6. Re: CFFILE Rename/Move Error?  Glitch?
                    BKBK Adobe Community Professional & MVP
                    >> Place the following tag at the top to remind Coldfusion about the XSL
                    >> extension
                    >> <cfcontent type="application/vnd.ms-excel">

                    > All that does is insert an HTTP header in the response, telling the client
                    > browser how to handle the data. It has no bearing on anything the CF
                    > server does, internally.


                    It does solve the problem.

                    • 7. Re: CFFILE Rename/Move Error?  Glitch?
                      insuractive Level 3
                      I think the real culprit here is Jakarta POI. I'm calling the Jakarta POI Java package from CF in order to process the excel file and convert the data into a CF query. My best guess is that the java object causes some sort of file locking which prevents me from renaming or moving the file using <cffile>. I've created a cleanup routine that I can run after my files have processed that allows me to go back in and rename the files at a later date.

                      I tried adding the <cfcontent> tag in various places like BKBK suggested, but I did not see a significant change in the results. I'm inclined to agree with Adam and it probably wouldn't have much effect in this particular case since I am not displaying the Excel file, but converting the data into a CF variable.

                      Thanks for everyone's help on this one. If I notice anything else with this implementation, I'll be sure to note it in this thread.

                      • 8. Re: CFFILE Rename/Move Error?  Glitch?
                        Level 7
                        >>> Place the following tag at the top to remind Coldfusion about the XSL
                        > >> extension
                        > >> <cfcontent type="application/vnd.ms-excel">
                        >
                        > > All that does is insert an HTTP header in the response, telling the client
                        > > browser how to handle the data. It has no bearing on anything the CF
                        > > server does, internally.

                        >
                        > It does solve the problem.

                        OK then, I'll bite.

                        How setting the mime type in the response header have any impact on
                        server-side activity?

                        --
                        Adam
                        • 9. Re: CFFILE Rename/Move Error?  Glitch?
                          MikerRoo Level 1
                          quote:

                          Originally posted by: insuractive
                          I think the real culprit here is Jakarta POI. I'm calling the Jakarta POI Java package from CF in order to process the excel file and convert the data into a CF query. My best guess is that the java object causes some sort of file locking which prevents me from renaming or moving the file using <cffile>. I've created a cleanup routine that I can run after my files have processed that allows me to go back in and rename the files at a later date.

                          I tried adding the <cfcontent> tag in various places like BKBK suggested, but I did not see a significant change in the results. I'm inclined to agree with Adam and it probably wouldn't have much effect in this particular case since I am not displaying the Excel file, but converting the data into a CF variable.

                          Thanks for everyone's help on this one. If I notice anything else with this implementation, I'll be sure to note it in this thread.



                          No this is not POI. This is either (1) you did not close the file properly after you were done in POI or (2) you did not allow enough time for WinDoze to actually release the file lock.

                          Go back and follow my original instructions (after making sure you close the file properly).

                          Cfcontent had absolutely nothing to do with this issue.
                          • 10. Re: CFFILE Rename/Move Error?  Glitch?
                            insuractive Level 3
                            Aha! Thanks MikerRoo! I went back and took a look at my implementation of POI and caught that I had not closed my FileInputStream. Doh! I now seem to have no problem renaming the file with <cffile>.

                            Thanks again!
                            • 11. Re: CFFILE Rename/Move Error?  Glitch?
                              BKBK Adobe Community Professional & MVP
                              Adam:
                              > All that does is insert an HTTP header in the response,
                              > telling the client browser how to handle the data. It
                              > has no bearing on anything the CF server does, internally.


                              Insuractive:
                              > I'm inclined to agree with Adam and it probably wouldn't have
                              > much effect in this particular case since I am not displaying
                              > the Excel file, but converting the data into a CF variable.


                              MikerRoo:
                              > Cfcontent had absolutely nothing to do with this issue.

                              Cfcontent may seem an unusual suggestion. It is not science.
                              It is an unusual response to Coldfusion's unusual message,

                              Attribute validation error for tag CFFILE.
                              The value of the attribute source, which is currently
                              "C:\Program Files\cigna\excel2querytest.xls", is invalid.


                              This tells us it may be possible Coldfusion temporarily fails to
                              resolve the excel mime-type. Hence the cfcontent, to prompt it to.

                              The problem is quite common. You don't need an application like
                              Apache POI to reproduce it. This simple experiment will do.
                              - create directory cigna in c:\Program Files
                              - rename any excel file to excel2querytest.xls and copy it to
                              c:\Program Files\cigna
                              - copy and run the code that Insuractive gave.

                              That should reproduce the problem. It usually helps to now
                              apply cfcontent.

                              Insuractive:
                              > I tried adding the <cfcontent> tag in various places
                              > like BKBK suggested, but I did not see a significant
                              > change in the results.


                              Did you actually check the cigna folder to verify whether,
                              with cfcontent, the file had been renamed.





                              • 12. Re: CFFILE Rename/Move Error?  Glitch?
                                insuractive Level 3
                                BKBK - Adding the <cfcontent> tag in this instance did not have an effect because the problem was due to the fact that I had not closed my FileInputStream, so Java was maintaining a file lock on excel2querytest.xls until my ColdFusion page finished processing.

                                It is my understanding that the <CFFILE> tag does not actually care about the MIME type of the file, as the actions it performs (move, rename, copy) occur at the OS level. However, I know a lot of people have had problems with <CFFILE> errors, so I'll keep your <cfcontent> idea in mind the next time I run into a problem with <CFFILE>.

                                Thanks again for all your help.
                                • 13. Re: CFFILE Rename/Move Error?  Glitch?
                                  Level 7
                                  > It is my understanding that the <CFFILE> tag does not actually care about the
                                  > MIME type of the file, as the actions it performs (move, rename, copy) occur at
                                  > the OS level.

                                  Correct. A file copy copies bytes (well, probably blocks, but you get my
                                  drift) from point A to point B. In fact with a "move" or a "rename", the
                                  file itself is never accessed: it's just an update to the file allocation
                                  table (or whatever it is now with NTFS, but similar concept). The file
                                  itself stays put, and is never read. However the OS checks to see if
                                  anyone is *using* the file before any one of these file ops can take place.

                                  The file type is never interpretted because it doesn't NEED to be
                                  interpretted. It OS doesn't *care* what application is needed to open a
                                  file when all it needs to do is move data around.

                                  And this is all before we stop to consider that <cfcontent> sets
                                  instructions for the CLIENT BROWSER rather that the SERVER OS anyhow.
                                  There is not client browser being involved in this process. So it simply
                                  isn't relevant.

                                  BKBK, I'm afraid to say: you're simply *wrong* on this one. That's OK,
                                  sh*t happens. But take it for what it is, and quit digging your hole
                                  deeper. MikerRoo got it in one with the "the file is still open" thing.
                                  We've all seen this with Excel (or many other apps): trying to do something
                                  at file-system level when some app still has the file open.

                                  For my own part I concede I've been little use on this thread other than as
                                  bullsh*t detector. I'm sorry I was not much help, but I can't abide by
                                  misinformation being presented as "the answer".

                                  At least insuractive got the issue sorted, which is the main thing.

                                  --
                                  Adam
                                  • 14. CFFILE Rename/Move Error?  Glitch?
                                    BKBK Adobe Community Professional & MVP
                                    Just curious. What do you make of Coldfusion's:

                                    Attribute validation error for tag CFFILE.
                                    The value of the attribute source, which is currently
                                    "C:\Program Files\cigna\excel2querytest.xls", is invalid.


                                    Oh, and did any of you do the test I suggested to reproduce the problem (without Apache POI's open file)?



                                    • 15. Re: CFFILE Rename/Move Error?  Glitch?
                                      MikerRoo Level 1
                                      Just for giggles, I ran your test (adding an automatic file copy at the end to reset the scenario).

                                      Ran 2000 renames with no problems.

                                      As for the error message, IT IS A BUG. PLEASE JOIN ME IN REPORTING IT AS SUCH.

                                      Cffile reports the exact same (almost useless) message for: (1) a missing file, (2) a file that is read only, (3) a file that the user and/or CF system account doesn't have system permission to touch, (4) a file that is locked by any thread (including the current CF thread!), (5) ACTUAL INVALID arguments (EG http://www.google.com/webhp)
                                      • 16. Re: CFFILE Rename/Move Error?  Glitch?
                                        BKBK Adobe Community Professional & MVP
                                        > Just for giggles
                                        Yes, just for giggles,

                                        getPageContext().getResponse().getResponse().setContentType(getPageContext().getServletCon text().getMimeType("C:\Program Files\cigna\excel2querytest.xls"));

                                        is more or less equivalent to one cfcontent functionality. Can you see a function call to a file that, as we know, might be locked? There is no doubt Coldfusion stumbles here. The server itself supplies the hint, "Attribute validation error for tag CFFILE. The value of the attribute source, which is currently "C:\Program Files\cigna\excel2querytest.xls", is invalid.". I therefore wonder why you can't perceive my asking whether Coldfusion does content-type validation as part of the <cffile action="rename"> process.

                                        What happens under the bonnet during <cffile action="rename">? Assuming Java, of course, then it would likely be java.io.File and renameTo(), whose function is platform-dependent. Platform-dependence means permissions, locks, file names and MIME come into play.

                                        > I ran your test (adding an automatic file copy at the end to reset the scenario).
                                        Ran 2000 renames with no problems.


                                        Did you also test without "adding an automatic file copy at the end to reset the scenario"?
                                        I get Insuractive's error message everytime. My system is MX7.0.2 (+ all updates and fixes) and Windows 2000 Professional SP4. I used Unlocker1.8.5 to check that there are no locks or handles on the file.

                                        There was a new development in the test. On several occasions the browser showed an error message that it was unable to open the page. Yet the renamimg occurred successfully in the background. I wonder what the effect of cfcontent is. More importantly, I wonder what validation Coldfusion does during the <cffile action="rename"> process.


                                        • 17. Re: CFFILE Rename/Move Error?  Glitch?
                                          Level 7
                                          > Just for giggles
                                          Yes, just for giggles,


                                          getPageContext().getResponse().getResponse().setContentType(getPageContext().get
                                          ServletContext().getMimeType("C:\Program Files\cigna\excel2querytest.xls"));

                                          is more or less equivalent to one cfcontent functionality. Can you see a
                                          function call to a file that, as we know, might be locked? There is no doubt
                                          Coldfusion stumbles here. The server itself supplies the hint, "Attribute
                                          validation error for tag CFFILE. The value of the attribute source,
                                          which is currently "C:\Program Files\cigna\excel2querytest.xls", is
                                          invalid."
                                          . I therefore wonder why you can't perceive my asking
                                          whether Coldfusion does content-type validation as part of the <cffile
                                          action="rename"> process.

                                          What happens under the bonnet during <cffile action="rename">? Assuming Java,
                                          of course, then it would likely be java.io.File and renameTo(), whose function
                                          is platform-dependent. Platform-dependence means permissions, locks, file names
                                          and MIME come into play.

                                          > I ran your test (adding an automatic file copy at the end to reset the
                                          scenario).
                                          Ran 2000 renames with no problems.


                                          Did you also test without "adding an automatic file copy at the end to reset
                                          the scenario"?
                                          I get Insuractive's error message everytime. My system is MX7.0.2 (+ all
                                          updates and fixes) and Windows 2000 Professional SP4. I used Unlocker1.8.5 to
                                          check that there are no locks or handles on the file.

                                          There was a new development in the test. On several occasions the browser
                                          showed an error message that it was unable to open the page. Yet the renamimg
                                          occurred successfully in the background. I wonder what the effect of cfcontent
                                          is. More importantly, I wonder what validation Coldfusion does during
                                          the <cffile action="rename"> process.




                                          • 18. Re: CFFILE Rename/Move Error?  Glitch?
                                            BKBK Adobe Community Professional & MVP
                                            Server problem at Adobe? I sent nothing from a newsgroup.

                                            • 19. Re: CFFILE Rename/Move Error?  Glitch?
                                              MikerRoo Level 1
                                              So, your contention is that cffile somehow gets confused, decides the file should have a mime-type of say "preposterous", notices that the file is xls, checks some magical mime-type table (which CF uses for nothing else), and sees that "xls" does not match "preposterous"?
                                              Then after doing all this extra work, WHICH CF DOES NOT DO WHERE IT WOULD ACTUALLY BE HELPFUL, cffile throws a generic and misleading error message?

                                              How come I can set an xls file to any mime type I want and download it without any errors? Conversely, I can set any file extension to "application/vnd.ms-excel" and CF downloads it to my browser with nary a peep.

                                              • 20. Re: CFFILE Rename/Move Error?  Glitch?
                                                BKBK Adobe Community Professional & MVP
                                                Mine hasn't warmed up to a contention yet. Just puzzling out what kind of validation Coldfusion would do with paths, and why it would choose to validate when confronted with any of the 5 exceptions you mention.