确保上传文件的文件大小上载发生之前比的maxRequestLength低? [英] Ensure file size of uploaded file is lower than maxRequestLength before the upload occurs?

查看:86
本文介绍了确保上传文件的文件大小上载发生之前比的maxRequestLength低?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个FileUpload控件,用户可以上传图片的形式。我可以保证上传的图片文件的大小大于配置的maxRequestLength的低载发生之前,并通过从文件时,尺寸过大被抛出这样prevent异常?

I've got a form with a FileUpload control where users can upload images. Can I ensure that the file size of the uploaded image is lower than the configured maxRequestLength before the upload occurs, and by doing so prevent an exception from being thrown when file size is too large?

我看着控制的PostedFile的CONTENTLENGTH最初的尝试是没有的文件已经提交成功。

My initial attempt of looking at ContentLength of PostedFile of the control was to no avail as the file is already submitted.

我在增加了maxRequestLength没有兴趣。

I have no interest in increasing the maxRequestLength.

推荐答案

从一个可用性来看,一个简单的信息,告诉人们不要将很长的路要走,以preventing的问题。

From a usability point of view, a simple message telling people not to will go a long way to preventing the problem.

您可能会尝试这个(因人而异):这只是一个提示浏览器,并且是依赖于浏览器支持的语法。隐藏字段显然需要立即precede您的文件输入(或在asp.net中,文件上传控制,检查标记在浏览器中,以确保)。

You could then try this (YMMV): It's only a hint to the browser, and is dependent on the browser supporting the syntax. The hidden field apparently needs to immediately precede your file input (or in asp.net, your File Upload control, check the markup in a browser to be sure).

<input type="hidden" name="MAX_FILE_SIZE" value="500" />
<input type="file" />

其中值是KB - 所以上述限制为半兆字节。有些浏览器不支持此,因此,您仍然需要检查它在服务器端,或者接受,有些人用奇/古/不同的浏览器仍可能试图提交过大的文件。

where the value is in Kb - so the above would limit to half a megabyte. Some browser's won't support this though, so you'll still need to check it on the server side, or accept that some people with odd/ancient/different browsers may still try to submit oversized files.

此网页并的也是这一

这篇关于确保上传文件的文件大小上载发生之前比的maxRequestLength低?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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