Suppose I want to upload a CSV file
using javascript and send that file to my REST API.
What can be the maximum size of the file that I can upload which can be handled by my API
?
I searched and somewhat got to know that file size cannot exceed 10Mb.
Please correct me if I am wrong.
you can located the input
tag using document.querySelector
or using jQuery $()
and in that tag there is a nested property called size
( input.files[0].size
) this property return the size of you file in a byte. from there all you need to is bind to the onchange
event of the input
, check the file size and if it's over 10MB alert a message and clear the input
document.querySelector('[type="file"]').addEventListener('change',function(e){ if(e.target.files[0].size > 10000000){ alert('file size greater then 10MB'); e.target.value = null } })
<input type="file"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.