• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to copy image from internet to local drive  RSS feed

 
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
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you certain that that is permissible? The images are copyrighted, after all.
 
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.
 
Bartender
Posts: 4181
22
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!