You should create a custom model binder that associates directly your uploaded file to a byte[] field in your model.
Example:
public class CustomByteArrayModelBinder : ByteArrayModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var file = controllerContext.HttpContext.Request.Files[bindingContext.ModelName];
if (file != null)
{
if (file.ContentLength > 0)
{
var fileBytes = new byte[file.ContentLength];
file.InputStream.Read(fileBytes, 0, fileBytes.Length);
return fileBytes;
}
return null;
}
return base.BindModel(controllerContext, bindingContext);
}
}
You also have to remove the default model binder, and add yours (in Global.asax.cs, inside the Application_Start method):
ModelBinders.Binders.Remove(typeof(byte[]));
ModelBinders.Binders.Add(typeof(byte[]), new CustomByteArrayModelBinder());
This code were retired from this good article: http://prideparrot.com/blog/archive/2012/6/model_binding_posted_file_to_byte_array
Best regards :)