aspose file tools*
The moose likes Servlets and the fly likes How save an image to file on HD and send to a client link to the file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How save an image to file on HD and send to a client link to the file?" Watch "How save an image to file on HD and send to a client link to the file?" New topic
Author

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

Alex Pi
Greenhorn

Joined: Jan 08, 2013
Posts: 17

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

Joined: Jan 10, 2002
Posts: 61761
    
  67

You need to use an HTTP uRL to address the image, not the file protocol.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
232

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Reda Mokrane
Ranch Hand

Joined: Jul 25, 2001
Posts: 237
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

Joined: Jan 08, 2013
Posts: 17

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

Joined: Mar 22, 2000
Posts: 12835
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How save an image to file on HD and send to a client link to the file?