Skip to content

Instantly share code, notes, and snippets.

@btompkins
Created December 11, 2012 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btompkins/4262408 to your computer and use it in GitHub Desktop.
Save btompkins/4262408 to your computer and use it in GitHub Desktop.
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