It's not a secret anymore!*
The moose likes I/O and Streams and the fly likes Downloading an Image from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Downloading an Image from servlet" Watch "Downloading an Image from servlet" New topic
Author

Downloading an Image from servlet

Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Hi, i have a servlet that does the following in it's doGet method:


I can't change the servlet code. I need a client that will read the image, i have already tried the following:

Although all of the bytes get through, the image created has width and height -1.
Can anybody help ?
Thanks,
Alex.


"Quoting yourself is stupid" - Me
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

That means it's not a valid image. If you save the contents to a file, can you then open the file in your default program for PNG images?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Rob Prime wrote:That means it's not a valid image.

Thanks for the response. That's impossible, because i download the exact same image (using that servlet) onto a j2me application and it shows.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

I'm not saying the image on the server is invalid. I'm saying the image on the client is invalid.
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
I just tried that. It's funny cause if i use a code i found on the internet to convert Image to BufferedImage, it's working, i can see the image. Thanks, i couldn't do it without your help

But... Once i remove the conversion, i don't see it anymore.

And i can't tell what happens there that makes it show. If i post the conversion method here, you think you can spot why i can see the image only after the conversion ?
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Ok, so if i do this:

Image image = Toolkit.getDefaultToolkit().createImage(data, 0, data.length);
Image img = image;

I can see "img" but not "image". Wierd.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Downloading an Image from servlet
 
Similar Threads
Networking question from Jonathan Knudsen - Beginning J2ME..
Networking question from Jonathan Knudsen - Beginning J2ME..
Retreiving an image using JDBC
bytearray image decoding
how to encrypt data into an image