PDA

View Full Version : Using filefield xtype



infernoz
1 Feb 2013, 10:13 AM
Hello,

I didnt receive any responses for my previous to inquiries (http://www.sencha.com/forum/showthread.php?255351 and http://www.sencha.com/forum/showthread.php?255186) so I'll rephrase and make my question more generic so perhaps more people can relate to my issue.

Has anyone used the filefield xtype before in their ExtJS applications? If so how are you using them, particularly how you are attempting to send the file to the server side for processing.

Thanks

scottmartin
3 Feb 2013, 2:01 PM
Your question is very generic. From the API:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.File

You are responsible for returning success from server.



<?php
echo '{"success": "true"}';
?>


Scott.

infernoz
4 Feb 2013, 7:24 PM
I am definitely returning a success:true from the server. However I think my problem is that what I am trying to return to the user is another file (file in, file out). Therefore I am setting the content type in the header of the response to 'application/vnd.ms-excel' . Could this be the reason why my success:true is not being read?

scottmartin
4 Feb 2013, 8:38 PM
Are you sending the type back? example:



// Sending headers to force the user to download the file
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: inline;attachment;filename="'.$reports_array['report_name'].'.xls"');

$objWriter->save('xls/'.$reports_array['report_name'].'.xls');
echo "{success:true}";


On the client side, just call window.open


success: function(xhr) {
window.open('xls/' + employee_report_name + '.xls');
},


Scott

infernoz
6 Feb 2013, 3:33 PM
It seems that I am sending the file contents itself in the response and flushing the responses' buffer. That flush seems to be the reason my success:true is not being sent back to the client.

My back end is Java/Spring so I'm doing something like



response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment; filename=\"" + spreadsheetName +"\"");
// copy spreadhseet contents into response //
response.flushBuffer();
//..... later on...... //
Map<String, Object> modelMap = new HashMap<String, Object>();
modelMap.put("success", true);
ModelAndView modelView = new ModelAndView("jsonresponse", modelMap);

return modelView;


The issue is I dont know of another way of returning the file to the client. Is there another way of doing this so the file contents gets sent to the client AND my model map with success:true gets sent too?