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.
Loading...
Related Quiz
- The process of dynamically adjusting transmission power levels to maintain a stable connection in wireless networks is known as ___________.
- What role does an Intrusion Detection System (IDS) play in network security?
- What is the purpose of HTTPS in web applications?
- In a large-scale e-commerce platform, how would you design indexes to optimize search queries on product attributes like name, category, and price?
- In a doubly linked list, each node contains a reference to the ___________ and ___________ nodes.