How do i POST/ PUT a large image to REST service

I am trying to post a 5MB size image in byte array format together with other data and send it to REST , on the REST service side it end up with "Empty" Object. However if i try with small images like few hundreds KB, REST service will successfully receive a complete object which contain the byte array as well. Is there any solution on this issue? No exception was caught during the process. Note: Im sending one image at a time.

Here is my model class.

public class PunchAttachmentModel
{
    public Guid attachmentuniqueid { get; set; }
    public String attachmentfilename { get; set; }
    public Guid filetypeuniqueid { get; set; }
    public DateTime attachmentdate { get; set; }
    public String attachmentremark { get; set; }
    public byte[] attachmentbinary { get; set; }
    public Guid punchitemuniqueid { get; set; }
}

My Post Async:
public async Task PostAsync(T t, string weburl)
{
var uri = new Uri(string.Format(weburl, string.Empty));
try
{
var httpclient = new HttpClient();
var json = JsonConvert.SerializeObject(t);
HttpContent httpcontent = new StringContent(json);
httpcontent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
var result = await httpclient.PostAsync(uri, httpcontent);
}
catch(Exception e){

}

}

**RestService Post **

    [ResponseType(typeof(PunchAttachmentModel))]
    public IHttpActionResult PostPunchAttachment(PunchAttachmentModel attachment)
    {..............................}

Answers

  • KennyLingKennyLing MYMember

    Anyone please help me on this issue.

  • JHDevJHDev USMember ✭✭

    Could be a size limit for Http Post on the server side, have you checked the size of your JSON after you serialize the 5MB file? It is even going to be much bigger due to the text format.

Sign In or Register to comment.