You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by sljm12 <sl...@singnet.com.sg> on 2006/11/13 07:06:21 UTC

retreving file size and file name

Hi all, have 2 questions.

Some background, I am writing a simple downloader that uses regular expressions to download files from a forum.

1. How do i retrieve the file size of the file that i am downloading?

2. The forum uses php, and the link to the files are usually something like "http://www.insertservername.com/attachment.php?123013" using a web browser for downloads the brower is able to know the resultant file name, how do i do that in HttpClient?

Pretty new to HttpClient and will appreciate any help.

Regards
Stephen

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: retreving file size and file name

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2006-11-13 at 14:06 +0800, sljm12 wrote:
> Hi all, have 2 questions.
> 
> Some background, I am writing a simple downloader that uses regular expressions to download files from a forum.
> 
> 1. How do i retrieve the file size of the file that i am downloading?
> 

Stephen,

If you want to find out properties of a remote entity (such as its
Content-Length, for instance) without actually retrieving it, you may
want to use HTTP HEAD. Target servers are expected to generate exactly
the same response header to an HTTP HEAD request if though it was a
regular HTTP GET, but they are not supposed not send the response body. 

Hope this helps

Oleg



> 2. The forum uses php, and the link to the files are usually something like "http://www.insertservername.com/attachment.php?123013" using a web browser for downloads the brower is able to know the resultant file name, how do i do that in HttpClient?
> 
> Pretty new to HttpClient and will appreciate any help.
> 
> Regards
> Stephen
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: retreving file size and file name

Posted by Roland Weber <RO...@de.ibm.com>.
Hi sljm12,

you can't retrieve the file size. If you're lucky, the server sends
a Content-Length header. Otherwise, there's no way to get it in
advance.

sljm12 <sl...@singnet.com.sg> wrote on 13.11.2006 07:47:47:

> Hi thanks for the reply, i am talking abt cases where certain forum 
> software hide the under the URL e.g http://someserver.com/a.php?121 
> where u can't tell the filename but it redirects to lets say a.jpg.

Disable "follow redirects". Handle the redirect in your application.
Use the last part of the redirect URL as the filename.

hope that helps,
  Roland

> --- Ìì²ÅºüÀê <me...@263.net> wrote:
> 
> > Hi 
> > 
> >    You can read the the Reponse Header("Content-Length") value. its
> > repsonse stream length. When you download file, then it's file size.
> > 
> > The filename is your request filename. For example  i request
> > 'http://www.ddf.com/download.exe' then brower would render
> > download.exe ...(M)
> > 
> > ----- Original Message ----- 
> > From: "sljm12" <sl...@singnet.com.sg>
> > To: <ht...@jakarta.apache.org>
> > Sent: Monday, November 13, 2006 2:06 PM
> > Subject: retreving file size and file name 
> > 
> > 
> > > Hi all, have 2 questions.
> > > 
> > > Some background, I am writing a simple downloader that uses
> > regular expressions to download files from a forum.
> > > 
> > > 1. How do i retrieve the file size of the file that i am
> > downloading?
> > > 
> > > 2. The forum uses php, and the link to the files are usually
> > something like
> > "http://www.insertservername.com/attachment.php?123013" using a web
> > browser for downloads the brower is able to know the resultant file
> > name, how do i do that in HttpClient?
> > > 
> > > Pretty new to HttpClient and will appreciate any help.
> > > 
> > > Regards
> > > Stephen
> > > 
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > httpclient-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > httpclient-user-help@jakarta.apache.org
> > > 
> > >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: retreving file size and file name

Posted by sljm12 <sl...@singnet.com.sg>.
Hi thanks for the reply, i am talking abt cases where certain forum software hide the under the URL e.g http://someserver.com/a.php?121 where u can't tell the filename but it redirects to lets say a.jpg.


--- ��ź��� <me...@263.net> wrote:

> Hi 
>   
>    You can read the the Reponse Header("Content-Length") value. its
> repsonse stream length. When you download file, then it's file size.
> 
> The filename is your request filename. For example  i request
> 'http://www.ddf.com/download.exe' then brower would render
> download.exe ...(M)
> 
> ----- Original Message ----- 
> From: "sljm12" <sl...@singnet.com.sg>
> To: <ht...@jakarta.apache.org>
> Sent: Monday, November 13, 2006 2:06 PM
> Subject: retreving file size and file name 
> 
> 
> > Hi all, have 2 questions.
> > 
> > Some background, I am writing a simple downloader that uses
> regular expressions to download files from a forum.
> > 
> > 1. How do i retrieve the file size of the file that i am
> downloading?
> > 
> > 2. The forum uses php, and the link to the files are usually
> something like
> "http://www.insertservername.com/attachment.php?123013" using a web
> browser for downloads the brower is able to know the resultant file
> name, how do i do that in HttpClient?
> > 
> > Pretty new to HttpClient and will appreciate any help.
> > 
> > Regards
> > Stephen
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> httpclient-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> httpclient-user-help@jakarta.apache.org
> > 
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org