• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mhtml file with images

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a mhtml file with embedded images. It is stored in a folder in local file system. I have a servlet in my web app that reads this .mht file using plain old file IO. This servlet sets the Content-Type to

message/rfc822

and then writes what it read from .mht file to the response. Problem is when client receives the response, it cannot see the image, appears as broken link. What is the correct Content-Type to be set for .mht files or there something else needs to be done?

Thanks
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to this this format is not widely accepted among the popular browsers.

Are you sure your browser can show these files?
Have you tried hitting it locally?
 
Deb Sadhukhan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I tried it locally. My browser IE can show the html and images fine.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you save the file (as streamed by the servlet) to your local hard drive, can you still open it and view it with your browser?
If not, maybe the file is being corrupted in the streaming process.

Also, are you setting the Content-Disposition header?
MSIE often disregards the Content-Type header and tries to figure out what the file type is by its file extension. Maybe setting a file name with an .mhtml ext will be enough for the browser to figure out what it is.
 
Deb Sadhukhan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben,

Does not look like the file is getting corrupted. If I do view source, only thing looks like is image data missing.

Setting

does not make any difference.

If I try the same thing in Firefox, it tries to download the file. But, if I set it to open automatically without asking, then Firefox saves the file in C:\temp and then opens it from C:\temp in a new tab using IE plug-in.

Interesting part is when I view source of this page (from IE tab), it does not have image data either, but image shows up. Looking at the properties of the image it indicates it's location is

mhtml:file://C:\temp\a.mhtml

.

Even if it works on Firefox, it does not resolve my problem as application suppose to be IE compatible. Did it out of curiosity.

Thanks
 
Deb Sadhukhan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found what was the problem. If the .mhtml file has spaces in the name, then images do not show up. Otherwise it works! Only thing I need to set is content-type to message/rfc822.

Can I say stupid MS bug? (mhtml being MS invented format)
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It could just be that your code doesn't support spaces in the file name.



The resulting header value should have quotes around the file name if you want spaces to be supported.

Try:
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Deb,

I tried reading a .mht file from a servlet and writing it to the response using BufferedInputStream . I have set the content-type to "message/rfc822".
But when I execute the servlet a blank page is displayed in the browser. Do I need to set anything else.

Kindly guide me as you were able to read and send the response to the client.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic