• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Tejas Tambe
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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
 
Gowrishankar Mudaliar
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!