-1

I have gzipped file which contains json file. When I access static JSON file with url it displays json in browser, but when I access gzipped files it downloads file, but I want browser to unpack and show it in the browser like in the first case. Help me please, How can I organize it? Is there any tutorial? Thank you very much.

Khach Xcho
  • 3
  • 1
  • 4

1 Answers1

4

If you expect your browser to unpack and instantly display a file with the ending *.gz - this will not work (unless you have a special plugin that would do that, similar to PDF files that are displayed within a browser).

The following approach will lead to tomcat compressing the mentioned mime types on the fly, you won't have to gzip the JSON file yourself (any modern Browser will then unpack the gzipped file on the fly):

Make sure that your Connector in server.xml looks something like this:

<Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8444"
compression="on" compressableMimeType="text/html,
text/xml,text/plain,text/javascript,text/css,application/json" />

(add the compression and compressableMimeType attributes)

Configure the compressableMimeType according to your needs. The type for JSON is application/json (according to What is the correct JSON content type?).

Community
  • 1
  • 1
reto
  • 8,367
  • 4
  • 47
  • 50
  • Hi, thank you for your help. I'm not sure I have explained the problem correctly. I have data.gz and have url for accessing it something like localhost:8080/static_data/data.gz. when I go by this url the gz file is being downloaded but I want it to be extracted and the content (in this case json file) to be shown in the browser, is it possible? – Khach Xcho Jul 26 '13 at 13:10
  • If you have a file with the ending *.gz it is normal behaviour to have your browser download this file. The "on the fly uncompressing" of your browser only works for files that were compressed "on the fly". Your file *.gz is compressed beforehand. – reto Jul 26 '13 at 13:16
  • so means there is no way to show json inside data.gz? – Khach Xcho Jul 26 '13 at 13:41
  • No, normally no browser will automatically unpack and display the contents of a gzipped file. – reto Jul 26 '13 at 13:43
  • okay, thank you very much, now please add your last comment into answer so I can accept it. – Khach Xcho Jul 26 '13 at 14:00