Skip to main content
OCLC Support

External archival file downloads

CONTENTdm supports end user downloading of archival master files if you have integrated the Archival File Manager into your workflow when creating the records. If your archival masters are stored on your CONTENTdm website or if you are using OCLC’s preservation service, then everything works seamlessly. If you have chosen to provide your master downloads from a web server external to OCLC, then the archival file download links will not work correctly. The problem is that the external link is not being resolved properly.

This JavaScript customization rewrites the HTML for the download link so that it will correctly resolve to your external web server URL. To make sure this script works on your CONTENTdm website you will need to make sure the download menu item label is matching the selector in the JavaScript.

Also note this example script has been written to run only for a specific collection (alias = “dc”). If you want this script to run in all collections on your site, remove the if clauses from the two addEventListener stanzas.

(function () {
'use strict';

  // helper function to extract archival download link of current item
  function getNewArchivalLink(collection,item) {
    return fetch('/digital/bl/dmwebservices/index.php?q=dmGetItemInfo/' + collection + '/' + item + '/json')
    .then(function(response) {
      // return dmGetItemInfo as JSON
      return response.json();
    })
    .then(function(json) {
      // extract download URL from dmGetItemInfo response
      const newTarget = json.fullrs.split('\n')[1];
      return newTarget;
    })
    .catch(function(error) {
      console.log('No archival link found: ' + error);
      return '#';
    })
  }

  // locates download link and replaces the target URL
  function swapDownloadLink(collection,item,downloadLink) {
    const archivalLinks = document.querySelectorAll('li > a[data-metrics-event-label*="Archival"]');
    // customize the value in "" above to match localized menu label on site
    for (let i = 0; i < archivalLinks.length; i++) {
      archivalLinks[i].href = downloadLink;
    }
  }

  //helper function to sequence fetch promise
  function updateArchivalLink(collection,item) {
    getNewArchivalLink(collection,item)
    .then (function(response){
      swapDownloadLink(collection,item,response);
    });
  }

  document.addEventListener('cdm-item-page:ready', function (e) {
    if (e.detail.collectionId === 'dc') {
      updateArchivalLink(e.detail.collectionId,e.detail.itemId);
    }
  });

  document.addEventListener('cdm-item-page:update', function (e) {
    if (e.detail.collectionId === 'dc') {
      updateArchivalLink(e.detail.collectionId,e.detail.itemId);
    }
  });

})();
  • Was this article helpful?