3 Replies Latest reply on Feb 26, 2018 5:58 PM by rlpowell

    Rest API: Why are page images (contentImages) coming back corrupt?

    rlpowell

      So I've got a page with images embedded in it (i.e. images added with the image icon, uploaded from my computer).

       

      I find the page's content ID and I do a GET on /v3/api/contents/1234 (if my URLs don't look quite like yours, that's because my company has re-branded things so just ignore that please).  To get the URLs for the image downloads I add X-Jive-Add-Api-Uris: true to the headers.

       

      In the resulting JSON we've got the content.text, which includes things like:

       

      <a data-api-href="https://connectme.mycompany.com/mycompany/v3/api/images/4036449" href="https://connectme.mycompany.com/servlet/JiveServlet/showImage/102-1353310-4-4036449/Screen+Shot+2015-1

      1-06+at+5.31.58+PM.png"><img class="image-1 jive-image" data-api-src="https://connectme.mycompany.com/mycompany/v3/api/images/4036449" height="997" src="https://connectme.mycompany.com/servle

      t/JiveServlet/downloadImage/102-1353310-4-4036449/1920-997/Screen+Shot+2015-11-06+at+5.31.58+PM.png" style="width: 620px; height: 322px;" width="1920"/>

       

      which has https://connectme.mycompany.com/mycompany/v3/api/images/4036449 in it to get the image data; great.

       

      We also in the JSON have:

       

        "contentImages": [

          {

            "id": "4036449",

            "ref": "https://connectme.mycompany.com/mycompany/v3/api/images/4036449?a=1519242598940",

            "size": 1387458,

            "width": 2194,

            "height": 1140,

            "type": "image"

          }

        ],

       

      which has basically the same URL.

       

      The problem is that that URL doesn't work.

       

      Specifically: if I use that URL from the browser, I get a 403.  If I use it from curl or from my API code, no matter what games I play with content encoding or whatever, the data is always bad.  The file starts with:

       

      0000000: 3f50 4e47 0a1a 0a00 0000 0a49 4844 5200  ?PNG.......IHDR.

       

      (that's a hex dump).

       

      But that's incorrect for a png; the file is corrupt, and nothing can view it.

       

      The correct PNG header is:

       

      0000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452  .PNG........IHDR

       

      If I copy all the cookies out of my browser, I can curl the URL that is displayed to the user, which is:

       

      https://mycompany.com/servlet/JiveServlet/downloadImage/102-1353310-4-4036449/1920-997/Screen+Shot+2015-11-06+at+5.31.58+PM.png

       

      and in that case it works, and the file is viewable.

       

      The Content-Type reported by the API for the bad file is text/plain, so I suspect some encoding problem, but I've no idea how to fix it.

       

      What is going on, and how can I fix it?

       

      I just want to download inline images from pages!