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.
__________________________________________________________