Accessing assets uploaded through wchtools

When you upload assets to your Watson Content Hub by using the wchtools command line interface, the asset path values for your files match the file paths from your local file system.

For example, if you have a file /tmp/wch/assets/images/test.png that you push into Watson Content Hub through

wchtools push --dir /tmp/wch

the resulting asset has an asset path value of images/test.png. You can access this file as a static resource by using the following URL pattern:

https://{API URL}/ images/test.png

where the API URL is constructed as Domain name/{path} where {path}= api/{Content hub ID}. You can construct the API URL by getting the Domain name and the Content hub ID from the Authoring UI or you can get the {API URL} from WCH Authoring UI. To get the Domain name, Content hub ID, or the API URL, open the User menu by clicking the drop down arrow near the user name and then click Hub information. The Hub Information dialog displays the information.

Accessing assets uploaded through the Watson Content Hub Authoring UI

When you upload assets to your Watson Content Hub by using the Watson Content Hub Authoring UI, the asset path values for your files are auto-generated by Watson Content Hub. Watson Content Hub constructs the individual asset path values by adding a unique path prefix to the name of your uploaded file. The prefix is added to avoid name collisions when you upload multiple files with the same name. You can obtain the ID for the asset from the Watson Content Hub user interface. Open the asset that you want and click the API Information icon below the asset.
You can also determine the asset path value by completing the following steps:

  1. Click the asset to open the asset details view.
  2. Obtain the asset ID from the browser URL.The browser URL contains the asset ID as query parameter named assetId. For example, the ID of the asset that is shown in the Authoring UI by URL
    https://www.digitalexperience.ibm.com/#/Authoring/Content/My-Assets/ibm.jpg?assetId=8b84892a-1cdb-4526-a126-dacd53ac67f7

    would be

    8b84892a-1cdb-4526-a126-dacd53ac67f7
  3. Load the asset metadata by using the Authoring asset service (API Explorer).

    Note: You must be authenticated to use the Authoring asset service APIs. If you are timed out or did not authenticate, an error is returned.

    When you provide the asset metadata in the authoring asset service, the corresponding URL would look like this

    https://{API URL}/authoring/v1/assets/8b84892a-1cdb-4526-a126-dacd53ac67f7

    where the API URL is constructed as Domain name/{path} where {path}= api/{Content hub ID}. You can construct the API URL by getting the Domain name and the Content hub ID from the Authoring UI or you can get the {API URL} from WCH Authoring UI. To get the Domain name, Content hub ID, or the API URL, open the User menu by clicking the drop down arrow near the user name and then click Hub information. The Hub Information dialog displays the information.

  4. Find the path property with the asset path value in the JSON record that is returned by this URL.
  5. Provide the asset path value from the JSON record in the following URL pattern to access the asset file as static resource.
    https://{Domain name}/{Content hub ID}/{asset-path}

    and replace {Domain name} with your tenant Domain name and {Content hub ID} with your Content hub ID. You can obtain your tenant Domain name and your Content hub ID values from WCH Authoring UI. Open the User menu by clicking the drop down arrow near the user name and then click Hub information. A pop-up window displays the Domain name and the Content hub ID. Replace {asset-path} with the asset path value that you retrieved in the previous step.

Support for relative URLs

Relative URLs are supported when addressing published assets as static resources using the path based URLs. The Delivery resource service API allows addressing resources via a path URL query parameter. This API does not support relative URLs. More information on the Delivery resource REST API, can be found here: API Explorer.

3 comments on"Accessing assets by their path"

  1. How would i download all images in a directory ?

  2. Michael Burati November 03, 2017

    Leon,
    I’m sorry this comment on the documentation was missed. If you could post your question on the Watson Content Hub developer forum (link below), it will be seen by more WCH experts, and hopefully get an answer more quickly. Please include clarification whether you mean download from the Watson Content Hub delivery CDN on Akamai, or do you mean pulling assets from the Authoring services with wchtools? Please tag your questions on the forum with WCH and “Watson Content Hub” so that those (including myself) monitoring the developer works forum will be notified about those questions and can respond more quickly.

    For searching in a directory, from JS in your web application, the Watson Content Hub Search API can search by path (including wildcard) or location (folder), eg, with query including classification:asset, fq=location:folderpath See the search sample at https://github.com/ibm-wch/sample-search-api for more information on various search queries.

    The wchtools CLI does not currently have a way to pull just assets within a given folder, but you can pull web assets with wchtools pull -w -v and managed content assets with wchtools pull -a -v . See more information about wchtools at: https://github.com/ibm-wch/wchtools-cli .

    Thanks and I hope this information helps,
    ..Mike Burati
    IBM Watson Content Hub and Digital Experience tooling
    https://developer.ibm.com/answers/smart-spaces/301/watson-content-hub.html

Join The Discussion

Your email address will not be published. Required fields are marked *