You're developing a web application where users need to upload images. How would you validate the file type and size using JavaScript?

  • Use File API to check file size
  • Use FileReader API to read file metadata
  • Use accept attribute in tag
  • Use typeof operator to check file type
Using the accept attribute in the tag allows specifying the allowed file types (MIME types) that users can upload. This provides client-side validation to ensure that only files of specified types are accepted. The File API, on the other hand, allows accessing file metadata, including size. Using typeof is not suitable for file type validation. The FileReader API is used to read file content, not metadata.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *