cesarulo
12 May 2007, 11:52 AM
Hey Community,
I am trying to get the browser to offer me a download dialog for server-side file content in response to a connection that was initiated with an Ext.data.Connection.request().
The server-side code is pretty much the same that was used in an old application. It sends the force-download headers:
header("Content-Type: application-x/force-download");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename=".$filename);
header("Content-transfer-encoding: binary");
and then barfs out the contents of the file in question.
This is working well; so well, indeed, that I can see the contents of my file in the responseText when I debug my connection callback function. The problem is now I don't know what to do with it. Besides, I don't really think storing it there is such a good idea; some of these server-side files could be huge. Is there a way I can, using javascript, force the browser to offer the user a download dialog and just make it relay the server's response directly onto a file on disk?
I guess one easy way out of this would be to, instead of using a Connection, simply put an anchor there: as there's a force-download Content-type being sent, the browser page containing the rich client will remain undisturbed. The problem with this is that there's a number of possible error conditions that could occur in the server side. I already have working code on the server that sends JSON-RPC headers and an informative message if it finds an error rather than attempt to force a download. The client successfully handles this and shows a pretty error message right now. If I put a link there, I lose the possibility of handling these conditions, and yet worse, any such condition that yields anything other than file content will wipe out the rich client and give the user a meaningless page with server gibberish instead. Not acceptable.
Any thoughts on this matter would be very appreciated. Thanks in advance,
I am trying to get the browser to offer me a download dialog for server-side file content in response to a connection that was initiated with an Ext.data.Connection.request().
The server-side code is pretty much the same that was used in an old application. It sends the force-download headers:
header("Content-Type: application-x/force-download");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename=".$filename);
header("Content-transfer-encoding: binary");
and then barfs out the contents of the file in question.
This is working well; so well, indeed, that I can see the contents of my file in the responseText when I debug my connection callback function. The problem is now I don't know what to do with it. Besides, I don't really think storing it there is such a good idea; some of these server-side files could be huge. Is there a way I can, using javascript, force the browser to offer the user a download dialog and just make it relay the server's response directly onto a file on disk?
I guess one easy way out of this would be to, instead of using a Connection, simply put an anchor there: as there's a force-download Content-type being sent, the browser page containing the rich client will remain undisturbed. The problem with this is that there's a number of possible error conditions that could occur in the server side. I already have working code on the server that sends JSON-RPC headers and an informative message if it finds an error rather than attempt to force a download. The client successfully handles this and shows a pretty error message right now. If I put a link there, I lose the possibility of handling these conditions, and yet worse, any such condition that yields anything other than file content will wipe out the rich client and give the user a meaningless page with server gibberish instead. Not acceptable.
Any thoughts on this matter would be very appreciated. Thanks in advance,