3 Replies Latest reply on Jun 11, 2014 2:04 PM by whoiskevin

    Add attachment to existing content with V3

    agentalpha

      I'm having trouble trying to add a new attachment to an existing piece of content.  I'm able to add this same attachment when creating a new piece of content but doesn't seem to work for existing content.  I've tried many different versions of the attachment JSON but regardless of what I try I just get a '415 Unsupported Media Type' error.  I'm sure I'm sure I'm missing something small but can't figure out what it is.  Ideas?

       

      attachment = {

      "attachments": [

              {

                "url": "http://i2.cdn.turner.com/cnn/dam/assets/140611080706-02-iraqi-civilians-flee-mosul-c1-main.jpg" ,

                    "doUpload": true,

                  "contentType": "img/jpg",

              }

          ]

      }

       

      jQuery.ajax({

      type: "POST",

      url: '/api/core/v3/attachments/contents/44238',

      contentType: "application/json",

      dataType: 'json',

      data: JSON.stringify(jiveDoc),

      complete: function(data) {

        console.log('done');

      }

       

        • Re: Add attachment to existing content with V3

          Make sure you are using application/json as the content type for your request

            • Re: Add attachment to existing content with V3
              agentalpha

              Thanks Nils, yea I've got the content type as application/json for the AJAX request. Although I was just looking into the Jive code for this end point (com/jivesoftware/api/core/v3/services/content/AttachmentService.java) and it looks like maybe it only accepts multipart/form?  So maybe for an existing doc you can't upload an attachment for a URL like this??  Seems weird if that's the case because it works fine with creating a new piece of content.

               

              @Path("/attachments")

              @Produces({"application/json"})

              public class AttachmentService extends AbstractService

              {

                protected AttachmentProvider attachmentProvider;

                protected CommonContentProvider commonContentProvider;

                protected MessageProvider messageProvider;

               

                @POST

                @Path("/contents/{contentID}")

                @HtmlWrap

                @Produces({"application/json", "text/html"})

                @Consumes({"multipart/form-data"})

                @RequiresAuthentication

            • Re: Add attachment to existing content with V3
              whoiskevin

              try "contentType":"image/jpeg"