Skip to content

Instantly share code, notes, and snippets.

@mastoj
Created October 11, 2011 07:53
Show Gist options
  • Save mastoj/1277518 to your computer and use it in GitHub Desktop.
Save mastoj/1277518 to your computer and use it in GitHub Desktop.
WcfWebApi Content-Disposition
public class JpgProcessor : MediaTypeFormatter
{
public JpgProcessor()
{
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/jpg"));
}
protected override object OnReadFromStream(Type type, Stream stream, HttpContentHeaders contentHeaders)
{
throw new NotImplementedException();
}
protected override void OnWriteToStream(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
{
var pathToImage= value as string;
var path = HttpContext.Current.Server.MapPath(pathToImage);
// This does not work!
contentHeaders.ContentDisposition = new ContentDispositionHeaderValue("attachment") {FileName = "test.jpg"};
using (var file = new FileStream(path, FileMode.Open))
{
file.CopyTo(stream);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment