Forums Register Login

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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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);
}
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1702 times.
Similar Threads
How do i download image files ? - MIME HEADERS HOW TO USE ??
MIME Headers - how to download image files.
URGENT!!
Help me resolve the error: HTTP Status 500
Mistakenly changed web.xml
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 05:50:14.