JavaScript file upload size validation

后端 未结 13 2428
眼角桃花
眼角桃花 2020-11-22 00:23

Is there any way to check file size before uploading it using JavaScript?

13条回答
  •  半阙折子戏
    2020-11-22 01:14

    It's pretty simple.

                var oFile = document.getElementById("fileUpload").files[0]; // 
    
                if (oFile.size > 2097152) // 2 mb for bytes.
                {
                    alert("File size must under 2mb!");
                    return;
                }
    

提交回复
热议问题