locked
Uploading Video/Audio along with other datafields to web API

    Question

  • Hi,

    Im trying to upload Audio/Video files to Web API using WIndows store App. I need to pass the video/audio info along with some other fields like name,description,Image and attachment.

    Im able to upload it successfully for file not exceeding 1MB or so. But I have requirement to upload more than 1MB files. Here is my snippet used .Client Side code.

     string methodhiturl = String.Format("api/TestV2/UplaodAttachemnt);
                        ContentObject obj = new ContentObject();
                        obj.longdescription = longDescription;
                        obj.Summary = yammerSummary;
                        obj.ImageBytes = imagebytes;
                        obj.ImageName = ImageName;
                        obj.attachmentName = attachmentName;
                        obj.attachmentBytes = attachmentbytes;
    
    
                        HttpContent content = new StringContent(JsonConvert.SerializeObject(obj));
                        HttpResponseMessage response = new System.Net.Http.HttpResponseMessage();
    
    
    
    
                        //response.Headers.Add("ContentLength",length.ToString());
                        //httpClient.DefaultRequestHeaders.Add("ContentLength", length.ToString());
                        response = await httpClient.PostAsync(methodhiturl, content);

    WebAPI code(Server Side)

    ContentObject info = JsonConvert.DeserializeObject<NewsContentObject>(await message.Content.ReadAsStringAsync());
                        string imageUrl = info.ImageName;
                        string attachmentUrl = info.attachmentName;
                        if (info.ImageBytes != null)
      //CODE TO SAVE IMAGE
                        if (info.attachmentBytes != null)
                            //CODE TO SAVE ATTACHMENT
    
    //WRITE TO DATABASE SNIPPET HERE

    I receive 500 Internal Server Error while performing this operation. I have requirement to write all the info in one set. Could some one guide me the effective way of performing this operation, Tried a lot.. But no luck..


    Thanks & Regards Tejaswi Chandrapatla

    Monday, April 21, 2014 3:35 PM

Answers