View Full Version : POST form data and get file

29 Aug 2012, 7:47 AM
I need to send data to the server, who's response is a file, so I cannot handle it with the standard AJAX method.

So far, I can send GET requests by adding an "url" parameter to the button, and, in the controller's button handler, I simply do this:

onGetPDF: function(button){
var win = button.up('window');
lUrl = button.href;
Ext.getCmp('pdfBox').update( '<iframe src="' + lUrl + '">' );

As you can see, I've created an "Ext.Box" in my view, then I update its content with an iframe. This is working well, but now I need to do the same, but instead of sending a GET request I need to do a POST, because I have to send a lot of text to the server.

29 Aug 2012, 10:05 PM
I usually do a simple POST-submit, generate the file server-side, store it in the file system, send the name of the new generated file as response and on Ext-side I have a callback-function on form.submit which takes the response, extracts the filename and then proceeds with your iframe-solution.

Works like a charm, only drawback is the generation of files in the filesystem so you'll have to clear up once in a while ....


30 Aug 2012, 2:52 AM
Thanks Florian, yes I thought about a similar solution, but I don't like to create temp files on server side. Hopefully someone finds a cleaner solution.

30 Aug 2012, 9:27 PM
You could store the POST data in a user-session and send the ID back to the user which then in turn embeds the iFrame calling your URL including the ID which then renders the PDF ... so no temporary files will be stored on the server ....

31 Aug 2012, 5:08 AM
Great! I like that idea.