从网上下载之前获取的图像文件大小 [英] Get Size of Image File before downloading from web

查看:194
本文介绍了从网上下载之前获取的图像文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从网上使用下面的code在我的控制台应用程序下载的图像文件。

I am downloading image files from web using the following code in my Console Application.

WebClient client = new WebClient();
client.DownloadFile(string address_of_image_file,string filename);

在code上绝对没问题。

The code is running absolutely fine.

我想知道是否有一种方法,我可以得到这个图像文件的大小之前,我下载了。

PS-其实我已经写了code键使履带其周围的网站下载图像文件移动。所以,我不知道它的大小提前。我想说明的是文件的已提取网页的源代码的完整路径。

PS- Actually I have written code to make a crawler which moves around the site downloading image files. So I doesn't know its size beforehand. All I have is the complete path of file which has been extracted from the source of webpage.

推荐答案

如果网络服务为您提供了一个的内容长度的HTTP标头那么这将是该图像文件的大小。但是,如果Web服务要流的数据给你(使用块编码),那么你就不会知道,直到整个文件下载。

If the web-service gives you a Content-Length HTTP header then it will be the image file size. However, if the web-service wants to "stream" data to you (using Chunk encoding), then you won't know until the whole file is downloaded.

这篇关于从网上下载之前获取的图像文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆