I have an ASP MVC application which I also use (as a requirement) as a web service for a mobile application.
I have a controller handeling most of the actions used by the mobile app returning json, which works fine.
But I’m not sure of how to handle the upload of a picture as byte[].
Can a controller action receive a byte[] ?
I was thinking of encoding the byte[] into a string and then decoding it back in the controller action.
But I tried the conversion back and forth but the new byte[] is always different from the or original byte[]
byte[] originalData = ... // picture as byte[]
string dataString = System.Text.Encoding.Unicode.GetString(data);
byte[] newData = System.Text.Encoding.Unicode.GetBytes(dataString);
Is there a beter way or should I just go ahead and receive directly the simple byte[] ??
There is a blog post from Scott Hanselman which contains everything to get you started with file uploads in MVC in a nice way: http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx