absolutely spot on, navigateToURL( request,"_self") did exactly what I wanted (displaying the download prompt rather than the image itself).
The only bad thing being that I didn't think of it before asking the question :) Thanks for the tip Ben, very much appreciated even if I do feel like a bit of a fool now! Jim. (Actually, I had tried something similar as part of the remoting call, but it failed due to something I didn't understand, probably the response was going straight back to flex as a remoting result - I didn't check it any further because it was about 1.30 in the morning at the time...) -----Original Message----- From: [email protected] on behalf of ben Sent: Wed 05/12/2007 21:42 To: [email protected] Subject: Re: [flexcoders] howto save image from flex app to local disk - any tips / ideas? The "attachment" in Content-Disposition would force the browser to download the image (rather than display it), if that's what you want you probably don't need to open in a _blank window, the blank window is useless since the browser will just download the image. Otherwise if you want to display it in a new window, you do need the _blank, but not the "attachement". Ben Jim Hayes wrote: > > > Greetings flexcoders, > > I have a need for my flex application to have a "saveimage" button > that enables the user to save an image of part of the application. > > I've been able to get this to work without too much trouble, but it > still needs a bit of polish so I thought I'd ask if anyone has any > insights or tips they'd like to share. > > Currently I encode the image as a jpeg in flex, then send that > bytearray to the server via remoting (I'm using flourine), where it is > saved to an image file in a temp directory. The remoting call returns > the url of an asp script and the name of the temp file in the querystring. > On receiving that url the flex app does a simple > flash.net.navigateToURL( request,"_blank"), whereupon the server > serves up the temp file with some suitable headers , e.g. something > like this. > > resp.ContentType = "application/octet-stream"; > resp.AddHeader("Content-Disposition", "attachment; filename=" + "\"" + > suggestedFileName + "\""); > resp.Cache.SetCacheability(HttpCacheability.NoCache); > resp.WriteFile(filePathToRead); > resp.Flush(); > > All of which is great, the user gets an open/save prompt for the jpeg > file as I hoped. > > The only rather ugly thing about it is that in IE a new window is > opened that then displays some rubbish about cancelled actions (???), > in firefox it's handled rather more elegantly by a new tab that opens > very briefly then closes itself down (Though I noticed my colleagues > copy of firefox raises a bizarre sequence of "open popup?" warnings, > which surprised me). > > All of which is to be expected from the way I've done it, but is there > a better way (that will work cross browser at least for the most part) ? > I'd really like for the user just to see the save/download prompt > without any extra windows/tabs, if at all possible. > > I'm mulling over whether loading the "filesave" url into a hidden > Iframe might work, but It's all rather out of my experience at the > moment and googling has thus far failed to reveal any obvious ways to go. > > If anyone can point me in the right direction then it would be most > helpful and much appreciated! > > tia, > > Jim. > > __________________________________________________________ > This communication is from Primal Pictures Ltd., a company registered > in England and Wales with registration No. 02622298 and registered > office: 4th Floor, Tennyson House, 159-165 Great Portland Street, > London, W1W 5PA, UK. VAT registration No. 648874577. > > This e-mail is confidential and may be privileged. It may be read, > copied and used only by the intended recipient. If you have received > it in error, please contact the sender immediately by return e-mail or > by telephoning +44(0)20 7637 1010. Please then delete the e-mail and > do not disclose its contents to any person. > This email has been scanned for Primal Pictures by the MessageLabs > Email Security System. > __________________________________________________________ > > ______________________________________________________________________ This communication is from Primal Pictures Ltd., a company registered in England and Wales with registration No. 02622298 and registered office: 4th Floor, Tennyson House, 159-165 Great Portland Street, London, W1W 5PA, UK. VAT registration No. 648874577. This e-mail is confidential and may be privileged. It may be read, copied and used only by the intended recipient. If you have received it in error, please contact the sender immediately by return e-mail or by telephoning +44(0)20 7637 1010. Please then delete the e-mail and do not disclose its contents to any person. This email has been scanned for Primal Pictures by the MessageLabs Email Security System. ______________________________________________________________________
<<winmail.dat>>

