3

I'm using ASP.NET Web API and I'm trying to figure out the best way to post an instance of PictureData object.

public class PictureData
{
    public Stream Data { get; set; }    
    public PictureType Type { get; set; }    
    public string EntityId { get; set; }
}

Is there a way to convert the object to stream and post as stream, or I should keep all properties strings and ints and post it as JSON? What's the best approach?

Nebojsa Veron
  • 1,407
  • 3
  • 19
  • 36
  • 3
    If you post it as separate fields (a standard HTTP post) then anybody can potentially use the data, and it's going to be fairly easy to consume and debug in most http application servers. If you use JSON then the situation is fairly similar, just the packing and unpacking is different. If you wrap it up as a custom stream (by binary serializing the object and then posting as a base64 encoded string, for example), then only your service will be able to consume it. As to which is best - well that's up to you. – dash Aug 13 '12 at 10:53
  • 1
    @Nebo to answer one of your question I would suggest you to read the article written by Henrik this will give you a good idea http://blogs.msdn.com/b/henrikn/archive/2012/02/24/async-actions-in-asp-net-web-api.aspx – HatSoft Aug 13 '12 at 11:08

1 Answers1

0

Post it as a stream (similar to a form post of application/x-www-form-urlencoded). application/x-www-form-urlencoded or multipart/form-data? suggests you should use multipart/form-data but both are worth a try.

Community
  • 1
  • 1
Adam Baxter
  • 1,903
  • 19
  • 33