Opening files without downloading

 

In the case of TIFF files, the Google Chrome and Microsoft Edge browser automatically downloads the file, and once the download is complete, the TIFF Viewer Extension opens the file automatically.

 

However, most document management systems are not going to download any file, as it may pose security risks or be restricted in general. The majority of these systems use Web APIs or other forms of requests to retrieve documents from a database and stream them to the client side.

The TIFF Viewer Extension can inspect the native JavaScript XHR (XMLHttpRequest) responses, the most commonly used JavaScript API to send/receive Web requests and fetch any data, such as documents.

This means that if you fetch a TIFF or PDF document using XHR (XMLHttpRequest or JQuery Ajax), the extension can open the document.

 

·         The solution supports opening documents in a new browser tab, in a new browser window and embedded in an IFRAME.

·         The solution supports Google Chrome and Microsoft Edge browsers both.

·         The solution supports GET and POST requests.

 

JavaScript Examples of how to fetch documents with XHR to open with TIFF Viewer extension:

 

In the following example, we use a simple XMLHttpRequest to get a TIFF document from an absolute URL. In this example, the Content-Type is specified by the Web Server, or automatically handled by the browser. When the xhr.onload fires (the request completes successfully), the Extension will automatically recognize the incoming file and open the document.

 

 

$("#mybutton").click(function (){ 

 

      var xhr = new  XMLHttpRequest(); 

      xhr.open('GET', 'https://www.blackice.com/tiffocx/test.tif', true); 

      xhr.responseType = 'blob'

      xhr.onload = function(e) { 

        // automatic opening

      }; 

 

      xhr.send(); 

 

}) 

 

        

Another JavaScript Example is when the URL is not a file, but a Web API, which writes a file (stream) to the response.

In this example, the Content-Type is specified by the server-side API. When the “successfires (the request completes successfully), the Extension will automatically recognize the incoming file and open the document.

 

 

function FetchFile() {

    $.ajax({

        type: "GET",

        url: "https://www.blackice.com/chromeExtensionDownload/Download.cshtml",

        cache: false,

            xhr:function(){// Seems like the only way to get access to the xhr object

            var xhr = new XMLHttpRequest();

            xhr.responseType = 'blob'

            return xhr;

        },

        data: { },

        success: function (r) {

            // automatic opening

        },

        error: function (xhr, textStatus, message) {

            // error handling

        }

    });

}

 

 

             

Please note the xhr.responseType is “blob” in both examples, which is required for the TIFF Viewer Extension to inspect the incoming response.

The Content-Type must be one of the following to let the Extension open the file:

 

·         image/tiff

·         application/tif

·         image/x-ioca

·         application/afp

·         application/pdf