Created
December 11, 2012 21:40
-
-
Save btompkins/4262408 to your computer and use it in GitHub Desktop.
This file contains 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 PngProcessor : MediaTypeProcessor | |
{ | |
public PngProcessor(HttpOperationDescription operation, | |
MediaTypeProcessorMode mode) : base (operation, mode) | |
{ | |
} | |
public override IEnumerable< string > SupportedMediaTypes | |
{ | |
get | |
{ | |
yield return "image/png"; | |
} | |
} | |
public override void WriteToStream(object instance, | |
Stream stream, | |
HttpRequestMessage request) | |
{ | |
var contact = instance as Contact; | |
if (contact != null) | |
{ | |
var path = string.Format(CultureInfo.InvariantCulture, | |
@"{0}bin\Images\Image{1}.png", | |
AppDomain.CurrentDomain.BaseDirectory, | |
contact.ContactId); | |
using (var fileStream = new FileStream(path, FileMode.Open)) | |
{ | |
byte[] bytes = new byte[fileStream.Length]; | |
fileStream.Read(bytes, 0, (int)fileStream.Length); | |
stream.Write(bytes, 0, (int)fileStream.Length); | |
} | |
} | |
} | |
public override object ReadFromStream(Stream stream, | |
HttpRequestMessage request) | |
{ | |
throw new NotImplementedException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment