• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Problem uploading excel file with Coldfusion 10

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
dfhuber2
Asked:
dfhuber2
  • 3
  • 2
1 Solution
 
_agx_Commented:
>> 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
 
dfhuber2Author Commented:
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
 
dfhuber2Author Commented:
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
 
_agx_Commented:
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
 
dfhuber2Author Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now