Question on Viewing & Transformation Service from a Hackathon participant

Options
Shahid M
Shahid M E Community Moderator
  1. To automatically create the publication for viewing while creating a file instance, do we have to add an extra field in the renditions array? And does the name of that rendition always have to be Brava Rendition ?
  2. As the viewer service requires a publication object to render the document in the browser, how should I get the publication object for a file instance?
  3. After creating a file instance with the Brava renditions, do we get back the publications object?
  4. Even if the create file instance API call returns the publications object, then also we won't be creating a new instance whenever we have to view the document, So, how to get the publications object for an already uploaded doc in CMS? Even in the doc it's not mentioned.

5. What is the api variable used in the viewing and transformation docs?

Best Answer

  • LazarescuA
    LazarescuA E Member
    #2 Answer ✓
    Options

    5. In order to instantiate the Viewer, you need a couple of steps:

    a. you will call the /viewer/api/v1/viewers/brava-view-1.x/loader endpoint that will return the right JS + CSS to load.

    Using your code, you will inject the above result as a script element in your header so that the browser loads them.

    b. you need to get your publication JSON object (see above)

    c. the above JS component has a lot of events that you can catch from your code. One mandatory event to catch will be the load event:

    You will need to store the event.detail (which will give you the actual api variable above). I stored it in a variable called bravaApi, for example.

    d. once the bravaApi variable is set, I can initiate the viewer and pass all the options (including the publication object) and then run it:

    The VIEWER_ID is a constant containing the div id where the viewer will be loaded.

Answers

  • Karen Weir
    Karen Weir E Community Administrator
    Options

    Thanks @Shahid M , our Engineering team is reviewing your post.

  • LazarescuA
    Options

    Hi @Shahid M ,

    I will answer each one below:

    1. To automatically create a viewer rendition, when creating the CMS object, you need to add a specific item in the renditions array. This specific item will be:

    {"name": "Brava rendition","mime_type": "application/vnd.blazon+json","rendition_type": "secondary"}

    The name can be anything you like, the mime_type and rendition_type need to be set to the values above.

    2. Indeed, the Viewer requires the Publication object. When the Viewer rendition is automatically created, the Publication JSON is stored in the CMS object as the secondary rendition. In order to get it, you need to first list the renditions ( cms/instances/<category>/<type>/<id>/contents ) and this will return all the renditions of the file. The result is an array of objects ($._embedded.collection[]) with information about each rendition. Locate the array item that is the Brava rendition (by mime_type, for example) and get the blob_id of that file.

    Use the CSS service with the blob_id and download the file. It is a text file containing the Publication JSON.

    Now, in your code, you need to parse this as a JSON object and pass that variable in the Viewer configuration.

  • LazarescuA
    Options

    3. Please see above, the Publication response is stored as a file rendition of the object. You need to download it and parse it.

    4. Correct, you will not create a new publication every time you view it, this is why we persist the information of the Publication at the level of the CMS object as a new rendition. The Publication details are stored as a text file.

  • LazarescuA
    LazarescuA E Member
    #6 Answer ✓
    Options

    5. In order to instantiate the Viewer, you need a couple of steps:

    a. you will call the /viewer/api/v1/viewers/brava-view-1.x/loader endpoint that will return the right JS + CSS to load.

    Using your code, you will inject the above result as a script element in your header so that the browser loads them.

    b. you need to get your publication JSON object (see above)

    c. the above JS component has a lot of events that you can catch from your code. One mandatory event to catch will be the load event:

    You will need to store the event.detail (which will give you the actual api variable above). I stored it in a variable called bravaApi, for example.

    d. once the bravaApi variable is set, I can initiate the viewer and pass all the options (including the publication object) and then run it:

    The VIEWER_ID is a constant containing the div id where the viewer will be loaded.

  • Shahid M
    Shahid M E Community Moderator
    Options

    @LazarescuA Thanks for answering all the questions in such great detail.