Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to copy image from internet to local drive

 
Joshua Elkino
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm wondering how difficult it is to grab an image off the web and copy it to the local server all through java.

This will be used with Google static maps where you can only use their service 1000 times a day. http://code.google.com/apis/maps/documentation/staticmaps/

To prevent exceeding the limit i was thinking of making the call once, then storing the image locally so that the call never has to be made again for that 1 page.

So the image would be located at something like this...
http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=12&size=400x400&maptype=mobile&key=MAPS_API_KEY&sensor=true_or_false
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you certain that that is permissible? The images are copyrighted, after all.
 
venkateshwar rao ravula
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this

URL url = new URL("http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=12&size=400x400&maptype=mobile&key=MAPS_API_KEY&sensor=true_or_false ");
InputStream is = url.openStream();
if(is!=null)
{
BufferedOutputStream outStream = null;
outStream=new BufferedOutputStream(response.getOutputStream());
byte by[] = new byte[32768];
int index = is.read(by, 0, 32768);
while (index != -1) {
outStream.write(by, 0, index);
index = is.read(by, 0, 32768);
}
outStream.flush();
outStream.close();




Thnks
RvRao
 
Joshua Elkino
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks i'll give it a shot.
As far as the copywrite issue... the image would still contain the watermark. I will have to talk it over with lawyers but i assume this is legit.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually their terms say you are not allowed to store the images locally except to pre-fetch for performance concerns. So you pretty much aren't allowed to fetch and store to get around their usage cap. I am no lawyer but I wouldn't count on it being allowed.


On the other hand, the 1000 upper limit is for unique images per viewer per day. If your viewers are looking at the same image 1000 times it doesn't affect quota, or if one user views 500 images it won't prevent another viewer from viewing 501 unique images. So are you going to gain anything from the server-side cache anyway?
 
Joshua Elkino
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good to know. Thanks Steve
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic