0 Replies Latest reply on Apr 12, 2016 7:48 AM by umesh

    API for photos into Jive cloud

    umesh

      Hello ,

       

      I am not getting temp image location from my code.

       

      code:

       

       

      static string updateImage(JivePersonObject person, byte[] imageBits)

       

      //upload image

       

      string jivePictureUrl = ConfigurationManager.AppSettings["JiveURI"];

       

      "api/core/v3/profileImages/temporary";           

       

      string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(ConfigurationManager.AppSettings["apiUsername"] + ":" + ConfigurationManager.AppSettings["apiPassword"]));

       

      string boundary = "-----" + DateTime.Now.Ticks.ToString("x");

       

      string HeaderTemplate = "--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n";

       

      string formKey = "filename";

       

      string header = String.Format(HeaderTemplate, boundary, formKey, "defProfileImage.jpg", "image/jpg");

       

      byte[] headerbytes = Encoding.UTF8.GetBytes(header);

       

      string responseString = string.Empty;           

       

      try

       

      "POST";

       

      true;

       

      "multipart/form-data; boundary=" + boundary;

       

      "Basic " + credentials;               

       

      using (Stream requestStream = request.GetRequestStream())

       

      byte[] newlineBytes = Encoding.UTF8.GetBytes("\r\n");

       

      byte[] endBytes = System.Text.Encoding.UTF8.GetBytes("--" + boundary + "--");

       

      using (WebResponse response = request.GetResponse())

       

      string tempImageLoc = response.Headers["Location"];                       

       

      using (StreamReader reader = new StreamReader(response.GetResponseStream()))

       

      //set profile image                                               

       

      string jivePeopleUrl = ConfigurationManager.AppSettings["JiveURI"];

       

      "api/core/v3/people/";

       

      "/images";

       

      using (WebClient client = new WebClient())                       

       

      "Basic " + credentials;

       

      "application/json";

       

      new System.Collections.Specialized.NameValueCollection();

       

      "imageURI", tempImageLoc);                           

       

      byte[] setImageResponse = client.UploadValues(jivePeopleUrl, myNameValueCollection);                           

       

      catch (Exception ex)

       

      throw new System.ServiceModel.Web.WebFaultException<string>(ex.Message, HttpStatusCode.InternalServerError);

       

      return responseString;