So have a modal/dialog box that I am doing an uplo...
# cfml-general
f
So have a modal/dialog box that I am doing an upload of a file, and then the file is compared to database data and a new Excel file is generated. This is all done in a component, however when I use cfheader/content to try to download the new excel file, it just does not seem to work in the component...I figured I can do this in a cfc function and not just in a .cfm file, but for some reason it is not working....any thoughts on using a cfc function to download a newly created excel file? thanks
d
At the risk of saying things you already now, there's no reason I'm aware of why the code being in a CFC or CFM should matter. Maybe add some logging to track where execution did and didn't get to. Also try a simplified standalone test to download and existing file via a CFC method. No errors in the logs I assume?
c
if you are directly calling CFC methods via HTTP things can be different with request lifecycle etc if i remember rightly
f
thanks guys, this is why I am asking since I can't seem to figure out why it would not work....any thoughts like these will help me for sure 🙂
a
Could you elaborate on what you mean by "it is not working" ?
you mean the header is not being set? It's erroring? What?
Have you pared the logic back to "return a file with a specific mime type via a cfm file" (works) and "return a file with a specific mime type via a call to a method in a CFC" (doesn't work). For some definition of "doesn't work".
f
It is just not downloading the file...if I save the excel file to my local temp folder I can see it, but the header/content tags don't seem to be working to help download it
a
So what is the response then? just... zero length doc? What's the mime type?
If I was to guess... you have already flushed the beginning of a response to the browser before getting to the cfcontent / header calls, so it's "too late" to change it.
f
not sure....mime time is set to vnd.ms-excel
filenameFullExt ="ram:///prReview_" & dateFormat(now(), 'mmddyyyy') & '.xls';
cfspreadsheet(action="read", src="#filenameFull#", name="local.xls"); cfheader( name="Content-Disposition", value="attachment; filename=MySpreadsheet.xls"); cfcontent( type="application/vnd.ms-excel", variable="#SpreadsheetReadBinary(local.xls)#");
crap, the code did not format correctly that I posted....
a
I don't mean what you're setting it to. I mean what the browser is actually receiving.
We know what it's supposed to be doing. We're trying to work out why it's not doing that. And first thing to check there... what is it doing instead of what it's supposed to.
f
sorry @Adam Cameron was pulled into a demo for my work...I will look and see what shows up in debug
I will have to get back to you on this later...in demo and when I tried to do an excel download something else might be wrong....you are keeping me on my toes 🙂
hey all, once I moved my spreadsheet code to a cfm file, it all worked....so not sure what the issues were, but found a way around
a
😞
f
I know, but was not going to waste alot of time...but I am still running all the queries in a component...just the spreadsheet stuff is in a cfm file
1
a
Yeah... and "get it working" is more important than "getting it nice", so: correct approach.
I hate not being able to work these things out though 😐
f
I totally agree...I tried for hours and then went to the cfm file to see if it would work, and it did...so I do have in my head this is something I will look to refactor...