1

I am receiving a base64 encoded string of a tiff image from the Java server side. Through ajax we are able to retrieve the string. But now we need to be able to display this encoded string of a tiff image on the browser as an image. How can this be done. I am not able to find any help to be able to decode the string on the client side using javascript. Any help would be appreciated as i have been working on this for a long time without being able to come a solution.

directly appending the encoded string to the src attribute does not work

<img src="data:image/tiff;base64,+string+">

Thanks, Marc

user2450679
  • 15
  • 1
  • 8
  • That is directly displaying the tiff image. My question is regarding a base64 encoded string of a tiff image. which has to be converted. – user2450679 May 07 '15 at 05:10
  • Are you trying to display it in Chrome or Firefox? If so, it's not going to work. Those browsers do not support TIFF. Chances are what you have is actually working it's just your browser can't display the image format – Phil May 07 '15 at 05:11
  • I had initailly used tiff.js to display it on chrome and firefox. but that was because i was directly importing the file from the local file system and used FileReader to read the file. But now the scenario is with the base64 encoded string. So is there a way to display the encoded string using any library? Would work on safari? – user2450679 May 07 '15 at 05:23
  • You need to manually parse TIFF files in browsers which doesn't support the format (which are [most](http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support)). You can load the file via AJAX (as arraybuffer) and pass it to tiff.js –  May 07 '15 at 05:40
  • Also see http://stackoverflow.com/questions/21797299/convert-base64-string-to-arraybuffer (just remember to remove the data-uri header) –  May 07 '15 at 05:42
  • Using AJAX to parse data-uri: http://jsfiddle.net/epistemex/q8qunygv/ (just note that some browsers sees data-uris as cross-origin and won't allow loading them with ajax) –  May 07 '15 at 05:52
  • @KenFyrstenberg when i tried your above suggestion, the browsers are throwing the below error in safari : InvalidCharacterError: DOM Exception 5: An invalid or illegal character was specified, such as in an XML name. In chrome : Uncaught InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded. Why is this error being thrown? – user2450679 May 08 '15 at 05:12

0 Answers0