JS Check the size of the uploaded file

Source: Internet
Author: User
var freader = new FileReader (), var input = document.getElementById (fileId); Freader.readasarraybuffer (Input.files[0]); Freader.onloadend = function (event) {var uri = event.target.result;if (uri.bytelength/1024/1024 >= 2) {alert ("more than 2M"); return;};}

Search on the Internet a lot of files on the size of the post has never been able to solve my problem, after reading an article FileReader, think of the file size is the sum of its bytes, so wrote this method. Tested by Firefox, Google is available.

JS Check the size of the uploaded file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.