Solved

Problem uploading excel file with Coldfusion 10

Posted on 2014-11-16
5
236 Views
Last Modified: 2014-11-17
I am trying to restrict the file type for an upload to excel only.  I have the following syntax, but it will not upload a .xls or a .xlsx file.
<cffile action="upload" fileField="form.LightingRetrofitXlsx" destination="#currentDirectory#"
                      nameconflict="makeunique" strict="true"
                accept="application/vnd.ms-excel" >

I have also tried:
<cffile action="upload" fileField="form.LightingRetrofitXlsx" destination="#currentDirectory#"
                      nameconflict="makeunique" strict="true"
                accept="application/vnd.ms-excel, application/octet-stream, application/excel, application/x-excel,application/x-msexcel,
                            application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" >

Is my syntax incorrect or is there a setting in the ColdFusion Administrator that I need to change to get excel files to upload.

I have uploads working for pdf files with:
<cffile action="upload" fileField="form.EnergyQuestionairePDF" destination="#currentDirectory#"
                      nameconflict="makeunique" strict="true"
                  accept="application/octet-stream, application/pdf, application/x-pdf" >
0
Comment
Question by:dfhuber2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 40446558
>> strict="true"

Any change if you use strict=false? Using strict=true means

the first few bytes of the file are read to determine the MIME type. If MIME type matches with what you have specified, upload occurs, else results in an error.

If you're getting an error, that suggests the first few bytes of the files aren't what they should be for the Excel XLS and XLSX mime types:

* application/vnd.ms-excel  
* application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

  What's the error message? Which program generated the files you're trying to upload?
0
 

Author Comment

by:dfhuber2
ID: 40447442
No, the excel files are still not loading when I try strict="false".  I have actually created most of the excel files that I have tried.  Some with created with programs like MS SQL Server 2008 R2 Reporting Services.  I have tried both .xls files and .xlsx files.

I have not done a dump after the attempt to upload.  Right now, the code is handling the issues, so I am not getting error messages as to what ColdFusion thinks I am uploading.
0
 

Author Comment

by:dfhuber2
ID: 40447719
Here is my complete code at this time:
<cftry>  
            <cffile action="upload" fileField="form.LIGHTINGRETROFITXLSX" destination="#currentDirectory#"
                      nameconflict="makeunique" strict="false"
                accept="application/vnd.ms-excel" >
 <cfcatch type="any">
            <cfoutput>
         <cfdump var="#cffile#">
</cfcatch>
</cftry>
No matter what type of file I try to upload, I get struct[empty].  However, if I use the above code for pdf, it works great.  PDF's are upload and non-pdfs get an appropriate message.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 40447884
EDIT:

Can you dump out the error message inside the cfcatch? So we can see what CF "thinks" is the problem. Maybe the problem isn't what we think. The error message should tell us more.

ie
<cfcatch type="any">
         <cfdump var="#CFCATCH#">
</cfcatch>
0
 

Author Closing Comment

by:dfhuber2
ID: 40448642
By doing the full dump, I noticed that I had missed the very important piece of having  "enctype="multipart/form-data"" in my form action statement.

Problem is that I was developing things when I was just too tired, so yes, the problem was not what I was thinking.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question