Getting the size of a file on the web

284 views
Skip to first unread message

kappa10j

unread,
Dec 31, 2011, 5:01:52 PM12/31/11
to Selenium Users
i,

I dont want t download a file. I just want to check if it's a certain
size. In my organization, 1 of 2 images could be shown on a webpage
(and these images will oth have the same name). I've tried to get the
size by using the content header but that doesn't provide an exact
value. And downloading the file first could be too time consuming in
certain instances (this would be a quick hack fix). Is there anyway
to get the file size?

thanks,
Jordan

I've tried
BufferedInputStream in = new BufferedInputStream(new
URL(url).openStream());
FileOutputStream fos = new FileOutputStream("file");
BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
byte data[] = new byte[1024];
while(in.read(data,0,1024)>=0)
{
bout.write(data);
}
bout.close();
in.close();

return new File("C:\temp\file").length();

but it takes too long for large files.

Tarun Bhadauria

unread,
Jan 2, 2012, 12:00:27 AM1/2/12
to seleniu...@googlegroups.com

kapp...@gmail.com

unread,
Jan 2, 2012, 4:40:49 AM1/2/12
to seleniu...@googlegroups.com
That only works for local files though.  I've tried to specify an URL but out doesn't work.


Sent via the Samsung Galaxy S™ II Skyrocket™, an AT&T 4G LTE smartphone.


-------- Original message -------- Subject: [selenium-users] Re: Getting the size of a file on the web From: Tarun Bhadauria To: seleniu...@googlegroups.com CC:

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/BZYvw68-vjMJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Benjamin Hawkes-Lewis

unread,
Jan 2, 2012, 5:11:14 AM1/2/12
to seleniu...@googlegroups.com
On Sat, Dec 31, 2011 at 10:01 PM, kappa10j <kapp...@gmail.com> wrote:
> I dont want t download a file.  I just want to check if it's a certain
> size.  In my organization, 1 of 2 images could be shown on a webpage
> (and these images will oth have the same name).  I've tried to get the
> size by using the content header but that doesn't provide an exact
> value.  And downloading the file first could be too time consuming in
> certain instances (this would be a quick hack fix).  Is there anyway
> to get the file size?

You cannot *verify* the size of a file without having the whole file,
which requires downloading it.

If downloading the images takes a long time, that seems likely to have
an impact on the end user too …

--
Benjamin Hawkes-Lewis

Reply all
Reply to author
Forward
0 new messages