Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

displaying images from file through Tomcat

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using the very simple HTML file to upload image from file:

When I open this html straight from the hard disk, everything work just fine (in IE7 or FireFox)
but if I put this HTML in Tomcat web-container and load it through URL to IE7 - it is able to dislpay only part of the files I am trying to load for preview.
It displays only part of the 'landscape' images (the width is larger) and none of the 'portrait' images no relation to the size of the images.
Still I managed, by the way, to upload to the server side (to a servlet) all the files that I tried to even those that IE refused to display in preview.
I can't figure out what Tomcat does that prevent the images from being displayed? (I compared the source files that IE read and it's the same)
Has anyone faced this weired problem?
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. So, is there any client-side expert who knows why in Tomcat 'file upload' behaves differently?
(very easy to reproduce this problem)

2. Has anyone else ever encountered similar problem?
 
Saloon Keeper
Posts: 24339
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It might be because I haven't the faintest idea of what you're trying to do there. I'd swear that you're expecting to upload the same file you just downloaded via an img reference.
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you are right -
here is what this HTML does:
when loading the HTML straight from the filesystem:
1.press the 'browse' button and select and image (jpg, bmp etc doesn't matter) that you have on your hard-disk
2. after selecting double click on the mouse
result: the image that you selected will be displayed as part of the html page (as the "pic1" element).

when loading the same HTML through TOMCAT:
1.press the 'browse' button and select and image (jpg, bmp etc doesn't matter) that you have on your hard-disk
2. after selecting double click on the mouse
result: most of the images will not be displayed on the page, some will be (around 10% according to an unknown rule)
 
Tim Holloway
Saloon Keeper
Posts: 24339
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat (or any other web server) cannot directly access files on your local computer and it would be a security nightmare if it could.

When you use the HTML file upload control, it builds a special POST request (you must place the fileupload tag in a FORM with a multipart mime-encoded request type). This request, when submitted, will cause your browser gather up all the updated control values in the form, read the file selected, encode it for transmission, and send the whole package to the webapp server. The server-side code is then responsible for handling the received data. Most commonly it will save the uploaded file data as a file in the server's filesystem, but it can do anything it wants to with the data. Just please don't write it into the WAR directory or any of its children.

HTML file upload does not employ JavaScript. I'm afraid your JavaScript is altering the normal operation of file uploading, and not for the better.
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, interesting.
So how can I be able to preview on the html page the selected image that the user would like to upload before submitting it?

I don't think that there is any security issue here- if the broswer agree to submit the content of the image file to the remote server, why won't it display the file to the user's own computer
through his browser?

another question is what does TOMCAT does to the html-page before sending it, that causes the browser to behave differently despite using the same code-
Is it because it is being read from a URL instead of from a file?

And last- how can you explain the fact that for some of the images my code does work and for some doesn't? If it was due to security restriction I believe that the code would not work completely.
It seems like it restrict the file to be load above some size, modification date or any other unknown category that I am missing...
 
Tim Holloway
Saloon Keeper
Posts: 24339
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guy Roth wrote:OK, interesting.
So how can I be able to preview on the html page the selected image that the user would like to upload before submitting it?

I don't think that there is any security issue here- if the broswer agree to submit the content of the image file to the remote server, why won't it display the file to the user's own computer
through his browser?

another question is what does TOMCAT does to the html-page before sending it, that causes the browser to behave differently despite using the same code-
Is it because it is being read from a URL instead of from a file?

And last- how can you explain the fact that for some of the images my code does work and for some doesn't? If it was due to security restriction I believe that the code would not work completely.
It seems like it restrict the file to be load above some size, modification date or any other unknown category that I am missing...



Tomcat itself modifies nothing. It will send exactly what you tell it to, no more no less.

I actually do get a preview when I upload images, but I think this is being provided by the particular file browser dialog I'm using with Firefox/Linux. It shows a thumbnail in the file browser dialog window. I thought Windows had that capability these days, but it may require setting some desktop options. Failing that, you'll need some JavaScript that can alter the DOM of the displayed page, and for that I'd have to RTFM the JavaScript docs. Nothing server-related.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic