Solved

Problem uploading excel file with Coldfusion 10

Posted on 2014-11-16
5
226 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
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now