5 Replies Latest reply on Jan 17, 2018 8:27 AM by itsallbroken

    View attachment to Document using API (Not download)

    itsallbroken

      Hi All,

       

      Not sure if this is even possible, i'm onprem and using v8. I would like to be able to attach an image to a document and then using the API display that image rather than download it

       

      Just to give an idea why, i'm using the API to pull out all documents from a specified group and then using that data to populate a slider plugin for the homepage, i would like to have a banner type image pulled at the same time to display within the slider, i can't figure out any other way of pulling this dynamically and part of the document so was hoping that i could use the attachment option to attach the banner image and pull that using the api.

       

      The attachments data is available but the url appears to link to a page that presents it as a download rather than viewing it..

       

      Hope the above makes sense?

       

      Thanks

       

      Gareth

        • Re: View attachment to Document using API (Not download)

          The preview functionality (like viewing an attachment in the UI) is not exposed to the API. It is actually possible to manually build the links to the preview, but you cannot retrieve the necessary ID though the API.

           

          At least that was the case when I last looked into this about a year ago.

          1 person found this helpful
          • Re: View attachment to Document using API (Not download)
            itsallbroken

            Hi Nils,

             

            Yes pretty much, or if there's an alternative way of doing it, having looked through the creation of documents this appear to be the only way to add an image to the document without having the image embedded in the doc.

             

            I need some way to associate an image to a document but make it easy enough for authors to be able to manage, so when they create the document they can also add in the image for the banner then the api will pull all of this together.

             

            The way i have managed this at the moment is to pretty much use static banner images and have them added to the slider at random, the ideal scenario would be to have each banner with it's own associated image, so when new banner documents are created in the future we wouldn't need to change any code.

             

            Hope that makes more sense?

             

            Thanks

              • Re: View attachment to Document using API (Not download)
                itsallbroken

                In case anyone else has this issue, i was able to resolve by doing the following, passing in the list item from a for loop, i run through the item and build the image url, i'm on-prem so not sure if that makes a difference?

                 

                function formatImage(slide) {
                     var image = "";
                     if (slide.attachments.length > 0) {
                          for (var i = 0; i <= slide.attachments.length; i++) {
                               if (typeof slide.attachments[i] != "undefined") {
                                    if (slide.attachments[i].contentType.indexOf("image") !== -1) {
                                         image = "/servlet/JiveServlet/download/" + slide.id + "-" + slide.attachments[i].id;
                                    }
                               }
                          }
                     }
                     return image;
                }