Sorry, I didn't realize the fileName I was passing in had several spaces tacked on the end of it. Guess that causes goofy things to happen. Thanks anyways.

Jan

Jan Gonsalves wrote:

Hey guys (and ladies), quick question.

I've been using HttpClient for about 4 months now. I feel pretty comfortable with using it to do many things. My question is a simple one. If I have an image I need to download (www.SomeProvider.com/PICTURES/somePic.jpg), how do I get it? I've had to get images from providers using POST, I've used the GET method with a query string, but this have no query string. I get a file which has the size I expect, but yet when I try to view it, it says that file does not exist. I'm doing something wrong I just don't know what. Here's what I use for code:
int nBuffSize = 1024*5;
int readBytes = 0;
long fileSize = 0;
String szUrl = "http://www.someURL.com/PICTURES/"; + fileName;
try{
//szFileName is the local path
File f = new File(szFileName);
if (f.exists()){
f.delete();
}
f.createNewFile();
java.io.FileOutputStream fio = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream( fio ,nBuffSize);
//XTBrowser is my object which uses HttpClient.
XTBrowser browser = new XTBrowser(szUrl, null, CAT);
browser.openConnection();
browser.setHeaderPairs("Host","www.someURL.com");
browser.configMethod(true, true);
browser.getMethod("GET").setPath("/PICTURES/"+fileName);
InputStream instream = browser.executeMethodStream(browser.getMethod("GET"));


CAT.debug("GetImage Writing Image! -- creating file: " + szFileName);
byte[] buffer = new byte[nBuffSize];
while (true){
if ((readBytes = instream.read(buffer)) == -1)
break;
else bos.write(buffer, 0 , readBytes);
}
bos.flush();
bos.close();
instream.close();
browser.closeConnection();


So what am I doing wrong? I just want to save the image to disk. Thanks in advance.

Jan


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to