CFFILE Upload/renaming issue

288 views
Skip to first unread message

Ross Valenti

unread,
Aug 25, 2011, 3:51:33 PM8/25/11
to cfu...@googlegroups.com
Hi folks, I'm hoping someone can help me with this issue.  I've been banging my head against my desk for two days now.

I have an application that allows users to upload files (mostly PDFs).  These files are later downloaded by other users.

Files with spaces in the file names were causing the browser to choke on the download, so I rewrote the script to remove all spaces from the filename, and then use CFFILE method="rename".

The problem I am encountering is that after I do this, the browser can no longer open PDF files - when opened through the browser, and Acrobat window pops up with a dialogue window telling me the file is corrupt or invalid.

When I upload a file with no spaces in the name (and thus no cffile re-naming), I can then open these files through my browser.

When I upload a file with spaces in the name, and then rename them, I CAN open these files directly through Windows Explorer, but, as mentioned above, when opened through my browser, Acrobat tells me they are corrupted.

I'm using fully patched CF8, Apache 2.2, Win 2008R2.  Browser is FF.

Any thoughts would be greatly appreciated.

Ross Valenti
Syracuse University

Ross Valenti

unread,
Aug 26, 2011, 10:53:59 AM8/26/11
to cfu...@googlegroups.com

Pete Freitag

unread,
Aug 26, 2011, 11:02:53 AM8/26/11
to cfu...@googlegroups.com
Hi Ross, can you post the code you are using to rename the file. Renaming the file shouldn't alter the file contents so I'm wondering if the wrong file is getting renamed perhaps.


--
Pete Freitag - Adobe Community Professional
http://foundeo.com/ - ColdFusion Consulting & Products
http://petefreitag.com/ - My Blog
http://hackmycf.com - Is your ColdFusion Server Secure?




--
You received this message because you are subscribed to the Google Groups "Central New York ColdFusion Users Group" group.
To post to this group, send email to cfu...@googlegroups.com.
To unsubscribe from this group, send email to cfugcny+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfugcny?hl=en.

Ross Valenti

unread,
Aug 26, 2011, 11:11:19 AM8/26/11
to cfu...@googlegroups.com
Pretty basic..

<cfif FindNoCase('  ',thisResult.serverFile)>
       
            <cfset newFileName = ReplaceNoCase(thisResult.serverFile, ' ', '','all')>
           
            <cfset thisDestination = application.placement.upload_path & '\' & newFileName>
            <cfset thisSource = application.placement.upload_path & '\' & thisResult.ServerFile>
           
            <cffile action="rename"
                    destination = "#thisDestination#"
                    source ="#thisSource#"
                    attributes="normal">
         </cfif>          

.I can't imagine what is causing this to happen.

Ross

Ken Cameron

unread,
Aug 26, 2011, 11:23:06 AM8/26/11
to cfu...@googlegroups.com

Ross,

 

Have you examined the ‘bad’ file to see if the contents look wrong??

 

I’m guessing that somewhere along the line the binary got converted to text or the other way around and the data got corrupted.  Key things like does the byte count match on the good and bad versions or do they differ??

 

 

-ken cameron, CCP.

Staff Leasing of CNY Inc 315-641-3600

SkyDiver: Zoo-602, A-8596, D-11839.

Skier: down & cross. English Hunter Rider. Scuba: wet & dry

mailto: kcam...@staffleasing-peo.com  Home DZ: FingerLakes Skydivers, Ovid NY

 

 

Ross Valenti

unread,
Aug 26, 2011, 11:35:03 AM8/26/11
to cfu...@googlegroups.com
It's a very generic PDF I use for testing (delete-me.pdf).

If I upload it as 'delete-me.pdf', everything works just fine. (no renaming necessary)

If I rename it 'delete me with spaces.pdf' & upload, the script successfully renames the file to 'deletemewithspaces.pdf', but when I try to open through my browser, Adobe pops the corrupt message.

BUT, if I upload 'delete me with spaces.pdf', then browse to the file with Windows explorer directly on the server, Acrobat opens the file 'deletemewithspaces.pdf' with no problems.

Ross

--
You received this message because you are subscribed to the Google Groups "Central New York ColdFusion Users Group" group.
To post to this group, send email to cfu...@googlegroups.com.
To unsubscribe from this group, send email to cfugcny+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfugcny?hl=en.

Ken Cameron

unread,
Aug 26, 2011, 11:42:02 AM8/26/11
to cfu...@googlegroups.com

If you tried to ‘save as’ instead of open via the browser, does that make a difference??

 

Just trying to isolate out the steps that work from those that don’t.

 

-ken cameron
Syracuse Model Railroad Club http://www.SyracuseModelRr.org/
CNY Modelers http://www.cnymod.com/

Finger Lakes Live Steamers http://www.fingerlakeslivesteamers.org/

Member JMRI Developer Team http://www.jmri.org/
mailto: kcam...@staffleasing-peo.com

In the Upstate New York US area of the world

 

 

Michael Sprague

unread,
Aug 25, 2011, 4:08:36 PM8/25/11
to cfu...@googlegroups.com
Hi Ross,

Something to try... open the PDF file in a text editor and look at the source.  Compare the two files (original and renamed).  I've seen situations where the application.cfc's onrequestend code is getting executed and appended to the end of a processed PDF file.  This caused the exact error you mentioned in one of my applications.  I wasn't doing a rename, so it might not be the same issue, but looking at the plain text of the PDF may point you to the problem.

-Mike

On Thu, Aug 25, 2011 at 3:51 PM, Ross Valenti <rval...@gmail.com> wrote:

--

Ross Valenti

unread,
Aug 26, 2011, 12:01:29 PM8/26/11
to cfu...@googlegroups.com
I compared the two files in Notepad ++, and they seem identical, and both seem to have proper EOF statements.

Great idea, but now I'm even MORE confused. ;)

Ross

Pete Freitag

unread,
Aug 26, 2011, 12:04:55 PM8/26/11
to cfu...@googlegroups.com
What is your cffile action=upload nameconflict set to? 

Try removing attributes="normal" from the rename. 

How are you serving the file back to the user, using cfcontent, or just through the web server.

Ross Valenti

unread,
Aug 26, 2011, 1:40:46 PM8/26/11
to cfu...@googlegroups.com
I added the attributes option when I was having problems.  Removing it does not change.

Name conflict is set to makeunique

Files are served with cfcontent & cfheader, thusly:

        <cfsilent>
      
           <cfheader name="Content-Disposition" value="attachment; filename=#thisUrl#">
          
           <CFCONTENT TYPE="application/unknown" FILE="#thisFileName#">
      
      
       </cfsilent>

Ross

Pete Freitag

unread,
Aug 26, 2011, 2:33:11 PM8/26/11
to cfu...@googlegroups.com
Ross does using type="application/pdf" in cfcontent make any difference?

--
Pete Freitag - Adobe Community Professional
http://foundeo.com/ - ColdFusion Consulting & Products
http://petefreitag.com/ - My Blog
http://hackmycf.com - Is your ColdFusion Server Secure?




rval...@gmail.com

unread,
Aug 29, 2011, 11:11:48 AM8/29/11
to cfu...@googlegroups.com
Adding the content type does not make a difference.

Here is something I've noticed, though - when I click on a file that has NOT been changed, Firefox prompts me to open the file and suggests using Adobe Acrobat. This file opens successfully.

When I try to open a file with a name that has been changed, Firefox suggests that i use FireFox to open it, which then pops an acrobat window, which then fails with the corrupted file notice...

Ross


On , Pete Freitag <pe...@foundeo.com> wrote:
> Ross does using type="application/pdf" in cfcontent make any difference?--
> Pete Freitag - Adobe Community Professional
> http://foundeo.com/ - ColdFusion Consulting & Products
>
>
> http://petefreitag.com/ - My Blog
> http://hackmycf.com - Is your ColdFusion Server Secure?
>
>
>
>
>
> On Fri, Aug 26, 2011 at 1:40 PM, Ross Valenti rval...@gmail.com> wrote:
>
>
> I added the attributes option when I was having problems.  Removing it does not change.
>
> Name conflict is set to makeunique
>
> Files are served with cfcontent & cfheader, thusly:
>
>        
>
>
>
>       
>           
>           
>           
>
>
>
>       
>       
>       
>

Jason Quatrino

unread,
Aug 29, 2011, 12:14:39 PM8/29/11
to cfu...@googlegroups.com, rval...@gmail.com
Have you tried reading the file with CFFILE after you've renamed it?
Give that a try and dump the CFFILE scope. You may find some clues in
the CFFILE. It sounds as if the file is becoming corrupted during the
rename. Perhaps a file extension issue?

Good luck!

Jason Quatrino
Web Developer
Hamilton College
jqua...@hamilton.edu
315-859-4956

Eric Sprague

unread,
Aug 29, 2011, 2:10:17 PM8/29/11
to cfu...@googlegroups.com

Hi Ross.  You've probably already tried this but just to cover all the bases how about this:

 

1.  Take a file that has spaces in its name and rename it manually instead of using the script you wrote.

2.  Upload it and then test whether you can successfully open it through the browser.

 

Eric

_____________________________________________________________ This email, including any attachment(s) to it, is confidential and intended solely for the use of the individual or entity to which it is addressed. If you have received this email in error, please notify the sender. Note that any views or opinions presented in this email are solely those of the author and do not represent those of O'Brien & Gere. O'Brien & Gere does not accept liability for any damage caused by any virus transmitted by this email. The recipient should check this email and any attachments for the presence of viruses. _______________________________________________________
Reply all
Reply to author
Forward
0 new messages