• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How save an image to file on HD and send to a client link to the file?

 
Alex Pi
Greenhorn
Posts: 17
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have BufferedImage buffer.
I know how to send this image to a client: And it works.

But i'd like to save this image to file and send to a client link to the file.
My following code doesn't work:


I don't see any png-file on the HD (in the application directory) and the link: <img src=\"out.png"></img> leads nowhere. I'd like to have an embedded image in html.


When i use above code i have next html:


when i click the src link (i see page source) i have next message:
The address wasn't understood
Firefox doesn't know how to open this address, because the protocol (c) isn't associated with any program.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use an HTTP uRL to address the image, not the file protocol.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34870
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\jpr\MyWeb\DynamicImg\build\web\out.png is on the filesystem of the server. It won't be the client's c drive. The URL would be something like
file://nameOfServer/jpr/...

I've seen this on UNIX and not windows so I'm not sure how the c: part works. More importantly, most servers are configured to prevent clients from directly accessing files on the file system. Could you offer a download or put it on a network share instead?
 
Reda Mokrane
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes firefox block links to local files, check

http://kb.mozillazine.org/Firefox_%3a_Issues_%3a_Links_to_Local_Pages_Don%27t_Work






-Reda>
 
Alex Pi
Greenhorn
Posts: 17
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You need to use an HTTP uRL to address the image, not the file protocol.

Thanks.

OK. What have i got at the moment?!


As a result i have such a link:

I understand this is a wrong approach because each odd client will receive html code and each even client will receive only one png image. (I call this servlet twice and produce a different responce).

This instance only for my training and this approach is good for only one client (for my own education).
But I'd like to pass to a client the link to the image file (not the repeated request to the servlet).
When i do like that i receive NullPointerException:


I have such a situation:


What do i wrong?
(Sorry for corrections)
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servers are NOT allowed to serve files from arbitrary locations in a URL.

Your choices are:

1. Store the file in a location where the server is allowed to access files.
-or-
2. Serve the file by a servlet. The URL must address the file serving servlet and include the file name/path.

The problem with

is that it does not specify a path so the file will go to the "current" directory.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic