The ApplicationOctetStreamCodec is already registered for IFile and
In the latest trunk, you can simply do this:
ResourceSpace.Has.ResourcesOfType<DownloadableImage>()
.AtUri("/ServeImage/{imageId}")
.HandledBy<ImageHandler>();
public class DownloadableImage : InMemoryDownloadableFile
{
public DownloadableImage(byte[] content){
OpenStream().Write(content, 0, content.Length);
}
}
public class ImageHandler
{
public OperationResult GetImage(int imageID) {
byte[] imageFile;
...
return new OperationResult.OK { ResponseResource = new
DownloadableImage(imageFile) };
}
}
Note that there's a bunch of other properties that let you set the filename
and the media type of the binary stream.
Seb
> The InMemoryDownloadableFile class ignores the setting for Options and
> always treats the disposition as attachment
> (DownloadableFileOptions.Save). I verified this in Fiddler. However
> I found that if I used the InMemoryFile class instead it served the
> file inline which in this case is what I needed.
The idea of the DownloadableFileOptions is to add support for the special
http headers IE recognizes for enabling or disabling the Open and Save
buttons in the download box. It's not implemented yet :)
IDownloadableFile always results in an attachment, and IFile always an
inline.
> Both
> InMemoryDownloadableFile and InMemoryFile seem to ignore the
> ContentType setting and thus always serve the files back as
> application/octet-stream, again verified by Fiddler.
I'll add a regression test to openbastard to test that behavior. Strange
thing is, the app/octet-stream is normally only used as a default. Which
host are you using?
Thinking of it, there should probably be a check in the codec that when you
set the mediatype, that mediatype is compatible with the Accept: header sent
by the client. Otherwise it could make for weird results.
> Even if I set it
> to one of the predefined media types (e.g. MediaType.TextPlain) I get
> the same behavior. IE doesn't care and serves the images just fine
> but FF throws up a download dialog even though the disposition is
> inline.
IE is doing sniffing there, firefox just executes teh default action for the
Content-Type: application/octet-stream
Will try and get a fix tonight
Seb
-----Original Message-----
From: open...@googlegroups.com [mailto:open...@googlegroups.com] On
Behalf Of Heath
Sent: 10 September 2009 14:55
To: OpenRasta
Subject: [openrasta] Re: Serving images via ApplicationOctetStreamCodec
Thank you Seb!! This works for the most part. I do have a couple of
notes for you.
btw I'm using OpenRasta 2.0.3079.352 and it ROCKS. Keep up the great