推荐的方法来检查上传的文件大小 [英] Recommended way to check file size on upload

查看:138
本文介绍了推荐的方法来检查上传的文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个支持文件上传的网络应用程序。我已经很熟悉检查服务器端的大小,但我想检查在客户端的文件大小。

我知道它的浏览器限制,我们不能访问文件属性出于安全原因。所以我已经尝试了swfupload和uploadify组件。两者都很好,满足需求。

但限制是取决于闪存,所以如果我的最终用户没有安装闪存,那么我最终会遇到一个问题。要求他们安装Flash是另一回事,但它的网站和用户群是巨大的。所以我不喜欢让他们安装flash的想法。

今天我遇到了gmail中的文件上传功能。并在没有安装Flash的情况下在浏览器(IE)中进行测试。我发现有趣的如果你上传一个大文件,他们做了回发,并立即返回文件大小过大的消息。



这是怎么可能的,他们如何在不下载整个内容的情况下找到文件的大小。我相信这一定是通过阅读HTTP头信息来完成的。我是对的吗?

所以这是我想要实现的确切功能。如果闪光灯已经安装,我可以使用uploadify来检查大小,否则可能会实施,从来没有听说过,技术使用的谷歌。

有人可以推荐我怎么做吗?

有人曾经遇到过类似的问题,你做了什么更新:

Gmail上传与FF安装在FF

p>



在IE浏览器中无法使用

解决方案

经过大量的搜索,我发现我们可以使用 maxAllowedContentLength 来限制ASP.Net应用程序中的上传大小。请记住,此设置仅适用于IIS 7或更高版本。



由于这是在IIS级别处理的,因此我们不需要处理服务器代码中的任何内容。如果大小限制超过,则会返回错误代码 404.13 。所以,你可以很容易地检查客户端的代码,以确定问题。

这是我已经做了处理大文件,如果未安装在客户端机。



希望这可能有助于某人。

有关此设置的更多信息,请阅读这个




I am working on a web application which supports file uploading. I am already familiar checking the size in server side, but i wanted to check the file size in a client side.

I know its a browser limitation that we cant access the file properties for security reasons. So i have tried both swfupload and uploadify component. Both are good and serve the needs.

But the limitation is both depends on flash, so if my end user not installed flash then i would end up in a problem. Asking them to install flash is another thing, but its a web portal and the user base is huge. So i don't like the idea of asking them to install flash.

Today i came across file upload functionality in gmail. And tested this in browser(IE) without having flash installed. What i found was interesting. If you upload a big file, they made a postback and immediately returning the message the file size is too large.

How this is possible, how they can find the size of the file without downloading the whole content.? I believe this must be done by reading HTTP header info. am i right?

So this is the exact functionality i wanted to implement. If the flash is installed already, i can use uploadify to check the size otherwise may be i ll implement-the-never-heardof-technique-used-by-google.

can someone recommend me how to do this?

anybody faced the similar problems earlier, what have you done??

Update:

Gmail upload with flash installed in FF

without flash in IE

解决方案

After lot of searching i found we can use maxAllowedContentLength to limit the upload size in ASP.Net applications. Remember this settings work only on IIS 7 or above.

Since this is handled in IIS level, we dont need to handle anything in server code. If the size limit exceeds, it will return the error code 404.13. So you can easily check the code in client side to determine the problem.

This is what i have done to handle the large files if the flash is not installed in the client machine.

Hope this may help someone.

For more info read about this settings, read this

这篇关于推荐的方法来检查上传的文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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