?
Solved

Problem uploading excel file with Coldfusion 10

Posted on 2014-11-16
5
Medium Priority
?
243 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 2000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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 …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

801 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