Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to upload image from device to Web Service in xamarin forms ?

AsfendYarAsfendYar USMember ✭✭✭

How to upload image from device to Web Service in xamarin forms ? I know how to capture or pick the image from the device but the issue is I don't know how to convert it into bytes and then upload it into the web service.

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    You can try these

    public static string Base64Encode(string plainText) {
    var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
    return System.Convert.ToBase64String(plainTextBytes);
    }

        public static string Base64Decode(string base64EncodedData) {
            var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
            return System.Text.Encoding.UTF8.GetString(base64EncodedBytes,0,base64EncodedBytes.Length);
        }
    
  • AsfendYarAsfendYar USMember ✭✭✭

    Can you tell me what this code does ... @AlessandroCaliaro

  • AsfendYarAsfendYar USMember ✭✭✭

    What is the purpose of string base64EncodedData that is passed as a parameter in the function ?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    To convert an Image to a string so you can send it with Ws

    Something like

    stackoverflow.com/questions/21325661/convert-image-path-to-base64-string

Sign In or Register to comment.