Win a copy of Rust Web Development this week in the Other Languages 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
Posts: 17
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to use an HTTP uRL to address the image, not the file protocol.
 
author & internet detective
Posts: 40913
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
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