0
votes

I am trying to display tiff image in the browser but it is not working when I am trying to read locally or if I am giving URL of any tiff image. Here is my code .

 <script type="text/javascript">
   var xhr = new XMLHttpRequest();
   xhr.responseType = 'arraybuffer';
   xhr.open('GET', " file:///home/aniketshivamtiwari/Desktop/tiffdocument.tif");


   xhr.onload = function (e) {
  var tiff = new Tiff({buffer: xhr.response});
  var canvas = tiff.toCanvas();
  document.body.append(canvas);
};
xhr.send();
 </script>

I am getting this error
XMLHttpRequest cannot load file:///home/aniketshivamtiwari/Desktop/tiffdocument.tif. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. (anonymous) @ (index):54

1

1 Answers

0
votes

The error message says it all, you cant load files from your local machine. Upload the file in your project folder and use absulote or relative reference to that.

i.e.: put the file under images/tiffdocument.tif xhr.open('GET', "images/tiffdocument.tif");