Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

asp.net - Cross-browser checking on file size at client side before uploading it to the server?

Client side validation is important to improve usability.

Is there any cross-browser way to validate the file size before uploading it to the server. I am using asp.net file upload control.

I found some third-party controls do that check:

http://ajaxuploader.com/Demo/simple-upload.aspx

and

http://demo.essentialobjects.com/Default.aspx?path=AJAXU

but How?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is now possible with HTML5's File API:

<script>
    var myFile = document.getElementById('myFile');
    var size;
    myFile.addEventListener('change', function() {
        size = this.files[0].size;
    });
</script>

This is supported by most of the latest browsers.

Internet Explorer supports this workaround involving ActiveX, but it requires lowering Internet Explorer's security settings, so it isn't really an option for most applications.

It takes more work, but use a Flash-based uploader such as SWFUpload if you really need to do this in IE9 or below. IE10 will (hopefully) add support for the HTML5 File API.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...