9 Replies Latest reply on Dec 17, 2014 11:55 PM by ketan_muneshwar

    REST API 3.3 (Jive7c3) multipart upload broken?

    it2000

      Whenever I try to upload something I get this error: "We're sorry but a serious error has occurred in the system."

      What did something change in the API or is this a bug?

       

       

      Command to reproduce the error:

      curl -v -u Username:Password --header "Content-Type: multipart/form-data; boundary=SNIP" -d $'--SNIP\r\nContent-Type: application/json\r\n\r\n{"type": "document", "subject": "New Document", "content":{ "type": "text/html", "text": "<body><p>Some interesting text</p></body>"}}\r\n--SNIP\r\nContent-Disposition: form-data; filename="filename.txt"\r\nContent-Type: text/html\r\n\r\nCONTENT\r\n--SNIP--\r\n'  "https://sandbox.jiveon.com/api/core/v3/contents"

       

      API Version according to https://sandbox.jiveon.com//api/version

      "jiveVersion" : "7.0.0.0 7c3",

      "version" : 3,  "revision" : 3,  "uri" : "/api/core/v3",

        • Re: REST API 3.3 (Jive7c3) multipart upload broken?

          You are missing the Content-Disposition header on both of your body parts, which is required.

           

          It's also much easier to let curl do the work for you, by using multiple "-F value" options, which tells it to do a multipart-form/data and automatically constructs a valid multipart message with an appropriate separator.

            • Re: Re: REST API 3.3 (Jive7c3) multipart upload broken?
              it2000

              Hi Craig,

               

              thanks for your reply - but I have absolutely no clue how to fix this issue.

              The "old" API ("version" : 3,  "revision" : 2,) does still work as I do expect it. If I replace "sandbox.jiveon.com" with "community.jivesoftware.com" then everything works fine.

               

              May I ask where I need to add more Content-Disposition header(s) and with which values? The current request looks like this:

              POST /api/core/v3/contents HTTP/1.1
              Authorization: Basic ...
              Host: sandbox.jiveon.com
              Accept: */*
              Content-Type: multipart/form-data; boundary=SNIP
              Content-Length: 289
              
              --SNIP
              Content-Type: application/json
              
              {"type": "document", "subject": "New Document", "content":{ "type": "text/html", "text": "<body><p>Some interesting text</p></body>"}}
              --SNIP
              Content-Disposition: form-data; filename="filename.txt"
              Content-Type: text/html
              
              CONTENT
              --SNIP--
              

               

               

              PS: "Content-Disposition is an optional header field." according to RFC 2183 - Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field

               

               

              @"It's also much easier to let curl do the work for you, by using multiple "-F value" options, which tells it to do a multipart/form-data and automatically constructs a valid multipart message with an appropriate separator."

              I have no idea how to add the application/json data when using "-F". I would be happy to get a working example.

                • Re: REST API 3.3 (Jive7c3) multipart upload broken?

                  Adding and adjusting the Content-Disposition header like the following worked for me:

                  curl -v -u username:password --header "Content-Type: multipart/form-data; boundary=SNIP" -d $'--SNIP\r\nContent-Disposition: form-data; filename="filename.txt"; name="foo"\r\nContent-Type: application/json\r\n\r\n{"type": "document", "subject": "New Document", "content":{ "type": "text/html", "text": "<body><p>Some interesting text</p></body>"}}\r\n--SNIP\r\nContent-Disposition: form-data; filename="filename.txt"; name="foo"\r\nContent-Type: text/html\r\n\r\nCONTENT\r\n--SNIP--\r\n'  "http://localhost:8080/api/core/v3/contents"

                   

                  I will follow up with Craig to see why the name field is now required.

                  1 person found this helpful
                    • Re: REST API 3.3 (Jive7c3) multipart upload broken?
                      it2000

                      Thanks for your reply. It does work also with "...\r\nContent-Disposition:;name=\r\n..." - so it is really the "name" parameter which is now required. It represents the "original field name in form" according to Content Disposition Values and Parameters. As a HTML form is likely never used when accessing the API it makes no sense.

                       

                      I hope that you update the API to conform to RFC 2183.

                      Without a name and filename parameter Jive needs to generate filenames but this shouldn't be too complicated.

                      • Re: REST API 3.3 (Jive7c3) multipart upload broken?

                        The name field is required so that Jive can know what to name your attachment, which will in turn become the default filename when someone tries to download it.  You need exactly one body part with a Content-Type of "application/json" (which will be the V3 metadata about the uploaded document itself).  All other body parts must have a Content-Disposition header with a name parameter.  (This is exactly analogous to what happens in the UI, where the upload logic includes this type of header).

                          • Re: Re: REST API 3.3 (Jive7c3) multipart upload broken?
                            it2000

                            Hi Craig,

                             

                            Your API looks like it is using RFC standards, but it is not. This makes it hard to use.

                             

                            Would you at least document that a Content-Disposition with a name field is always required in each part of a multipart requests, even if no file is transmitted? Imho this requirement is silly and it is sad that a great company ignores RFCs.

                             

                            PS: One of these requests fails and it may be really hard to explain why:

                            curl -v -u u:p --header "Content-Type: multipart/form-data; boundary=SNIP" -d $'--SNIP\r\n
                              Content-Type: application/json\r\n
                              Content-Disposition: form-data; filename="filename.txt"; name="foo"\r\n\r\n
                              {"type": "document", "subject": "New Document", "content":{ "type": "text/html", "text": "<body><p>Some interesting text</p></body>"}}\r\n--SNIP--\r\n'  "https://sandbox.jiveon.com/api/core/v3/contents"
                            curl -v -u u:p --header "Content-Type: multipart/form-data; boundary=SNIP" -d $'--SNIP\r\n
                              Content-Type: application/json\r\n\r\n
                              {"type": "document", "subject": "New Document", "content":{ "type": "text/html", "text": "<body><p>Some interesting text</p></body>"}}\r\n--SNIP--\r\n'  "https://sandbox.jiveon.com/api/core/v3/contents"
                            
                    • Re: REST API 3.3 (Jive7c3) multipart upload broken?
                      ketan_muneshwar

                      HI,

                       

                      We are facing problems with, file upload of other than .txt file like (image/jpeg, application/pdf, image/png etc...).

                      Files are getting uploaded but, other than .txt files are corrupting, its not able to  view open the files.

                       

                      Is there any parameters we  are missing in request?

                       

                      The curl we are  using  as below:

                       

                      curl -v -u username:password --header "Content-Type: multipart/form-data; boundary=SNIP" --data-binary $'--SNIP\r\nContent-Type: application/json\r\n\r\n{"type": "document", "subject": "New dsdsdfdfsdDocument", "content":{ "type": "text/html", "text": "<body><p>Some interesting text</p></body>"}}\r\n--SNIP\r\nContent-Disposition:form-data;name="Sumit";filename="s.jpg"\r\nContent-Type: image/jpeg\r\nContent-Length:445265\r\nContent-Transfer-Encoding:binary\r\n\r\n' --data-binary '@line.jpg' --data-binary $'\r\n--SNIP--\r\n'  "https://XXXXXXXXXXXX.jiveon.com/api/core/v3/contents"

                       

                      partial response of above command

                       

                      "attachments" : [ {

                           "id" : "3572",

                           "resources" : {

                             "self" : {

                               "allowed" : [ "GET", "DELETE" ],

                               "ref" : "https://XXXXXXXXXXX.jiveon.com/api/core/v3/attachments/3572"

                             }

                           },

                           "contentType" : "image/jpeg",

                           "name" : "s.jpg",

                           "size" : 445267,

                           "url" : "https://XXXXXXXX.jiveon.com/api/core/v3/attachments/3572/data",

                           "doUpload" : false,

                           "type" : "attachment"

                         } ]

                       

                      Regards,

                      Ketan Muneshwar