• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URGENT !!! How Do I download Image files using HTTP.

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to download a file using HTTP. Text files and HTML files are getting downloaded perfectly, but not any other files.
I refered Complete Reference Java 2, I found that MIME Header has something to do with this, but was not clear.
So can any 1 help me in this regard.
Thanx in advance,
Tejas
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you are using text based input streams to download text and html files. If u want to read binary files like images,zip,exe files etc. use a binary stream. A code like this will help you.
int a;
URL url = new URL("http://www.abc.com/abc.jpg");
URLConnection urlConnection = url.openConnection();
InputStream i = urlConnection.getInputStream();
FileOutputStream fos = new FileOutputStream("abc.jpg");
while((a=i.read()))
{
fos.write(a);
}
 
Tejas Tambe
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx vgauri,
Logically speaking reading in byte arrays should be the solution, but the thing is that for HTTP download, this does not really works. When we send the request we need to specify the MIME type, to download the image files. And this is what I don't know how to do it.
The solution that you have given , that i have already tried. It does not help.
Does any body know anything about the MIME header types ???
Thanx anyway V
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't have to specify anything different when downloading an image file. What you are permitted to do is check the mime-type the server reports that the file is. Some programs (internet explorer jumps to mind) ignore the mime-type and use only the file extension to distinguish jpeg's from gif's from tiff's. The mime-type is just another way of distinguishing file types.
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic