18 Replies Latest reply on Sep 25, 2017 12:41 PM by klas

    Use upload new image rest call

    snigdha.challa

      In this link - Jive REST Rest API v3.6 → Image service  I see that we can use a rest call to upload an image. Is there an example to see how to use this api ?

       

      Im not clear as to what this takes ?

       

      According to the link -

      Takes:
      • multipart/form-data body that includes the uploaded image

       

      Why does it say "uploaded image" in the above line ? I'm confused - coz are we not uploading the image ?


      Whereas the first line in the article says "Upload an image as a multipart/form-data request body". How to do this ?

       

      Ryan Rutan could you please share your thoughts on this ? I am trying this out in relevance to the corporate directory photos that we consulted you about.

       

      Can you please provide me with an example so it helps me understand how to make this request. (For example: what are the parameters going to be for the ajax call)

        • Re: Use upload new image rest call

          REST API v3 Examples have you seen this document?  it shows how you can use the content-type headers and boundaries to make a multipart request using the cURL command.  Let me know if that doesn't help. =)

            • Re: Use upload new image rest call
              snigdha.challa

              Thanks Ryan Rutan for the reply.
              Can we do this using a simple ajax call that does the image upload - without using CURL ?

              • Re: Use upload new image rest call
                snigdha.challa

                Ryan Rutan I am trying to understand how I could use the Rest API call - But I am getting two errors.

                 

                I am trying to use the Rest API call to upload a new image. /api/core/v3/images . But I am getting a 403 Forbidden error error. Can anyone help me understand why I am getting this error ?

                 

                {"message" : "The request could not be validated as originating from within the SBS application",   "code" : 4026 }   .


                I have the below code in the canvas.html of my app which I have deployed as an add-on. I go to this page by directly clicking on the app (under the Apps menu).

                 

                <form name="multiform" id="multiform" action="https://company-specific-url.com:10443/api/core/v3/images" method="POST" enctype="multipart/form-data">

                                <input type="file" id="fileuploadfield" name="fileuploadfield"/><br/>

                                <input type="submit" value="Submit" class="btn btn-inverse btn-small"/>

                </form>

                <script>
                
                   $("#multiform").submit(function(e)
                  {
                  var formObj = $(this);
                  var formURL = formObj.attr("action");
                  var formData = new FormData(this); //first check if its not null
                
                   $.ajax({
                  url: formURL,
                  type: 'POST',
                  data: formData,
                  crossDomain: true,
                  mimeType: "multipart/form-data",
                  contentType:  "multipart/form-data",
                  cache: false,
                  processData: false,
                  xhrFields: {
                  withCredentials: true
                  },
                  dataType: 'json',
                  beforeSend: function (xhr){
                  xhr.setRequestHeader('Authorization', 'Basic ' + btoa("username:password"));
                  },
                  success: function(results){
                  console.log("entered here success - snigdha");
                  }
                  error: function(xhr, status, error) {
                  console.log("entered here fail - snigdha");
                  }
                  });
                  });
                  </script>
                
                

                 

                 

                How do I get access to the Rest APIs from outside SBS applications (through apps etc or if I am using a stand-alone application) ?

              • Re: Use upload new image rest call
                amit.mahajan

                I am getting the same error while trying to upload an image

                 

                {"message" : "The request could not be validated as originating from within the SBS application",   "code" : 4026 }   .