0 Replies Latest reply on Nov 12, 2018 12:10 PM by Sachin Patil

    Unable to post images using api/core/v3/images/

    Sachin Patil

      Hi I'm unable to post images using .net API and getting 400 error code.

       

      flowing code spinet used to post image:

       

      public Image CreateImage(string filename, Stream stream)

              {

                  Image resultImage = null;

                  List<string> errorMessages = new List<string>();

                  //if (ParamUtil.Validate(image, out errorMessages))

                  {

                      MultipartFormDataContent form = new MultipartFormDataContent();

                      form.Add(addStringContent("type", "file"));

                      form.Add(addStreamContent(stream, filename));

       

       

                      HttpResponseMessage message = _access.DoPostWithTokenAuthentication(_access.GetImageUrl(), form);

                      Task<string> task = message.Content.ReadAsStringAsync();

       

       

                      HandleErrorsByResponse(message);

       

       

                      resultImage = Newtonsoft.Json.JsonConvert.DeserializeObject<Image>(task.Result);

                  }

                  return resultImage;

              }

       

      public HttpResponseMessage DoPostWithTokenAuthentication(string url, MultipartFormDataContent content)

              {

                  HttpClient client = GenerateHttpClientWithTokenAuthentication();

                  return DoPost(url, client, content);

              }

       

      private HttpResponseMessage DoPost(string url, HttpClient httpClient, MultipartFormDataContent multipartFormDataContent)

              {

                  url = CheckUrlNoEndSlash(url);

       

       

                  httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("image/png"));

       

       

                  Task<HttpResponseMessage> task = httpClient.PostAsync(url, multipartFormDataContent);

                  Task<string> task2 = task.Result.Content.ReadAsStringAsync();

       

       

                  JiveManagerBase.HandleErrorsByResponse(task.Result);

       

       

                  return task.Result;

              }

       

       

      Bad Request - {

        "error" : {

          "code" : "attachmentInvalidType",

          "status" : 400,

          "message" : "The specified image content type application/gzip is invalid"

        }

      }