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
Solved

Problem uploading excel file with Coldfusion 10

Posted on 2014-11-16
5
234 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_
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ROBOFTP UNZIP 1 53
Coldusion - DATA insert syntax problem 12 49
Lucee & <cftransaction.... />  WITAF? 10 16
List all Printers with anmes and Ip address 3 27
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

808 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