locked
How to pass WriteableBitmap image to a rest service?

    Question

  • Actually I've rotated an image through WriteableBitmap.rotate(180)  and saved in PictureLibrary. Now i want to upload this Image to server using a rest service by implemneting HttpClient class.

    Thanks,

    Pankaj Kumar Verma

    Tuesday, September 2, 2014 12:42 PM

Answers

  • I was able to save and open image locally without any issue.

     i resolved the problem. Problem was at service end. stream need to be read in chunks.

    Thanx for replying.

    regards,

    pankaj

    Wednesday, September 3, 2014 7:56 AM

All replies

  • Tuesday, September 2, 2014 1:06 PM
  • Actually i am already able to upload  but image is getting corrupted.

    My code is as follows-

    StorageFile f = await WriteableBitmapToStorageFile(writeableBitmap, FileFormat.Bmp);

                string local = f.Path;
                string url = "http://10.4.1.189/RestDemoServices/DemoService.svc/FileUpload/RotatedCheck.bmp";
                HttpClient client = new HttpClient();
                
                IBuffer buffer = await FileIO.ReadBufferAsync(f);

                StreamContent content = new StreamContent(buffer.AsStream());

                content.Headers.Add("Content-Type","image/bmp");
                
                using (HttpResponseMessage response = await client.PostAsync(url, content))
                {
                    string respString = await response.Content.ReadAsStringAsync();
                    messageBox(respString);
                }

    Tuesday, September 2, 2014 1:33 PM
  • Hi,

    just a though... have you tried saving the image local first and check if its corrupted? 

    Tuesday, September 2, 2014 5:21 PM
  • There's one sample here which deals with the same issue.

    Uploading an image using WCF RESTFul service


    Happy Coding!

    Tuesday, September 2, 2014 5:37 PM
  • It seem like your file gets corrupted please check the image locally by re-opening the image file that is create and furthermore sometimes the file name also causes a lot of problems please check that also please do check on the file name cause when i was creating an imaging app i stuck for 7 days i tested each and every piece of code but in the end it was just the file name which was causing all the problem in my case also it corrupts the image.

    Thank you.

    Muhammad Asad

     
    Tuesday, September 2, 2014 6:11 PM
  • I was able to save and open image locally without any issue.

     i resolved the problem. Problem was at service end. stream need to be read in chunks.

    Thanx for replying.

    regards,

    pankaj

    Wednesday, September 3, 2014 7:56 AM