EC5 Media (Public)

Testing EC5 API

by ParanoidAndroid77

HTML

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<img id="img" width="256">

JavaScript

var mediaEndpoint = 'https://five.epicollect.net/api/export/media/ec5-photo-example?';

 function _getEntries() {
   window.setTimeout(function() {
     $.ajax({
       url: 'https://five.epicollect.net/api/export/entries/ec5-photo-example',
       type: 'GET',
       contentType: 'application/vnd.api+json',
       success: function(response) {
         var entries = response.data.entries;
         var images = [];
         var filename;

         $(response.data.entries).each(function(index, entry) {
           filename = entry.photo;

           _getMedia(mediaEndpoint + 'type=photo&format=entry_original&name=' + entry.photo)
         });
       },
       error: function(xhr, status, error) {
         console.log(xhr.responseText);
       }
     });
   }, 1000);
 }

 function _getMedia(fileUrl) {

   var myImage = document.querySelector('img');
   
   //uncomment and add the token to the headers if the project is private
   var token = '';
   var myHeaders = new Headers();
   myHeaders.append("Authorization", 'Bearer ' + token);
   var myInit = {
     method: 'GET',
     headers: myHeaders, //uncomment when project is private
     mode: 'cors',
     cache: 'default'
   };

   fetch(fileUrl, myInit).then(function(response) {
     return response.blob();
   }).then(function(myBlob) {
     var objectURL = URL.createObjectURL(myBlob);
     myImage.src = objectURL;
   });
 }
 
 _getEntries();