aspose file tools*
The moose likes Servlets and the fly likes How to copy image from internet to local drive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to copy image from internet to local drive" Watch "How to copy image from internet to local drive" New topic
Author

How to copy image from internet to local drive

Joshua Elkino
Ranch Hand

Joined: Jul 24, 2007
Posts: 91
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
Marshal

Joined: Mar 22, 2005
Posts: 41489
    
  53
Are you certain that that is permissible? The images are copyrighted, after all.


Ping & DNS - my free Android networking tools app
venkateshwar rao ravula
Greenhorn

Joined: Apr 03, 2006
Posts: 15
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

Joined: Jul 24, 2007
Posts: 91
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

Joined: Jan 28, 2003
Posts: 4174
    
  21

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?


Steve
Joshua Elkino
Ranch Hand

Joined: Jul 24, 2007
Posts: 91
Good to know. Thanks Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to copy image from internet to local drive