1

I have a problem and I hope that you could help me. I'm using struts2 and I have an action like that:

<action name="myAction" method="cimas" class="MyClass" >
<result name="success" type="stream">
<param name="contentType">image/jpeg</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">inline;filename="${filename}"</param>
<param name="bufferSize">1024</param>
</result>
</action>

Until here everything's perfect, I set from my class the inputStream using this code:

filename = "anImage.jpg";
File img = new File("D://anImage.jpg");
inputStream = new FileInputStream(img);

and the image shows correctly, but the problem appears when I try to display an imagen with tif format. I change the path of the image, the filename and I set the contentType to:

<param name="contentType">image/tiff</param>

But it doesn't work and I wonder why. Can anybody help me?

Edit:

I edited the answer to explain what I did to resolve the problem.

As many users said to me, tiff format isn't for web use. Inspite of it, with IE and AlternaTIFF I accomplished to show the image. But as I wanted a solution for all browsers finally I converted the image to jpg and I displayed it using ImageMagick.

Thanks all for your help.

Airenin
  • 47
  • 1
  • 8
  • Thanks for your answer. The problem is that I have a lot of images and all of them are in the client machine so I can't convert them. My real issue is that I want open these images but I don't know how can I that cause as I said they are in the client machine. – Airenin Jan 17 '14 at 14:20
  • [This](http://stackoverflow.com/a/15278402/573032) solution might help you if you choose the proper content type. It will not affect files on the client machine. – Roman C Jan 17 '14 at 15:34

2 Answers2

2

Most browsers and email apps can not display TIFF images. Need to stick to PNG, JPG, or GIF for Web interfaces.

BrianC
  • 1,793
  • 1
  • 18
  • 26
  • Thank you very much for your answer. As I said to @hichris my real problem is that I want to display some images that are in the client machine to the user, but I don't know how can I do that. Could you help me please? thanks again. – Airenin Jan 17 '14 at 14:27
  • If we are talking about a web browser on the client machine they can not access local files on the client. The only thing you could do is upload the files to the server and then view them in line in a page. – BrianC Jan 18 '14 at 08:03
2

The solution is convert it to JPEG, PNG, GIF, or SVG otherwise in long term it will have issues.

TIFF image format is not designed for web use; it’s used for printing. Examples of image formats for the web are JPEG, PNG, GIF, and SVG.

Why are certain image formats suitable for the web, while others aren’t? Because images on the web must be optimized and highly compressed so that they don’t get too huge.

Some digital image formats, especially those designed for print (such as TIFF) are so unnecessarily high in resolution, metadata, and color-richness — which all become irrelevant when viewed in computer monitors — that they are too big in file size for web use.

Ricardo
  • 7,921
  • 14
  • 64
  • 111
  • Thank you @Ricardo, do you know how can I open local images that are in the client machine? First I tried to do it using the Desktop Java class but it doesn't work and I don't know how can I display the images to the user, cause I don't know how can I open them. – Airenin Jan 17 '14 at 14:24
  • As @RomanC said, his link should be useful, if you still have problems maybe you should ask another question pointing the new problem. – Ricardo Jan 17 '14 at 16:27