views:

2120

answers:

2

Hi all,

I am a newb developer as far as Flex and Flash is concerned. This is what I'm trying to do:

1) Send a HTTP request to our server (with a custom made URL). The URL basically tells the server to send data in a CSV format. 2) The server sends a 200 OK response, which has Content-Type: application/csv and the payload is pure CSV data.

What I wish to do is, when firefox gets this 200 OK response, I want it to show the standard Open with box (the one that shows up when you download some file).

I tried doing this with HTTPService. I have a "Export to CSV" button on the flash component. Upon clicking that, the flash component is able to succesfully send the HTTP request. I however don't want Flash component to handle the response, so I don't have the 's "result" tag defined. But nothing happens. Any suggestions on how to do this.

A: 

You will need Flash to at least respond to the request, then you call navigateToURL to go to your file, something like this:

private function resultHandler(event:ResultEvent):void
{
    navigateToURL(new URLRequest('createdFile.csv','_self'));
}
CookieOfFortune
A: 

Your server needs to send a header along with the file:

Content-Disposition: attachment; filename=foo.csv

Edit: let's clarify that with an explanation:

When you do this:

navigateToURL(new URLRequest('foo.csv'), '_self');

You're indirectly actually asking the browser to get foo.csv. Now, in order for the browser to show the Save dialog, it needs to know the data should be treated as an attachment. The header:

Content-Disposition: attachment

accomplishes just that. But often you also want to let the browser know the file name (and the file type, by way of the extension), which is why you add the filename bit after the semicolon.

Rytmis
Hey Rytmis,Thanks a lot. The combination of navigateToURL and Content-Disposition worked. Kudos!!!
Kash
Perhaps you could accept my answer, then? :)
Rytmis
Thanks, this was helpful. One correction I have is the "window" parameter is actually a parameter of the navigateToURL function and not a parameter to the URLRequest object. So it should look like this...navigateToURL(new URLRequest('foo.csv'),'_self');
Kevin
Thanks, fixed that. Gee, this question really makes me feel like posting an answer -- not only did the OP not accept it, I'm getting downvotes too, even though the answer is, in fact, correct (apart from the misplaced parenthesis). :D
Rytmis