1

I have problem to write a POST request to upload an image from Xamarin Forms to API. I already have my selected photo in format byte array, but I have problem with POST request, code is below, any suggestions?

At firts I select photo in my gallery at mobile phone, I save it to variable like byte array, then I must to send it to API like POST, but here I have problems because I dont know how to write correct code to be working.

            var zeton = await SecureStorage.GetAsync("Zeton");

            var httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUrl);
            httpWebRequest.ContentType = "multipart/form-data";
            httpWebRequest.Headers.Add("Token", zeton);
            httpWebRequest.Method = "POST";


            Stream stream = httpWebRequest.GetRequestStream();

            stream.Write(array, 0, array.Length);
            stream.Close();
blazk
  • 13
  • 3
  • 1
    Yes I do, but I cant do it – blazk Oct 14 '20 at 22:32
  • @blazk You could have a try with follow [sample code](https://learn.microsoft.com/en-us/dotnet/api/system.net.httpwebrequest.contenttype?view=netcore-3.1#examples) and modify the Type with your needs to check whehter it works. – Junior Jiang Oct 15 '20 at 02:47
  • @blazk Also could have a check with this discussion:https://stackoverflow.com/questions/3890754/using-httpwebrequest-to-post-data-upload-image-using-multipart-form-data?lq=1 – Junior Jiang Oct 16 '20 at 08:53

0 Answers0