Created
October 11, 2011 07:53
-
-
Save mastoj/1277518 to your computer and use it in GitHub Desktop.
WcfWebApi Content-Disposition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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