Handling File Uploads on the Frontend With JS: Preview, Size, Dimensions, and Format
What I hate most when uploading a file is being told five minutes later that the file is too big or the dimensions are wrong! We usually leave upload validation to the backend, so a file has to be uploaded before we can check whether it meets the requirements. Images in particular also need their aspect ratio checked. If all of this is left entirely to the backend, the user experience can suffer. When I was researching profile picture uploads at NewTalk, I found that all of this can actually be handled on the frontend. With JS and HTML5 APIs, you can check the file’s format, size (20MB), and dimensions (100x100). You can even do previews and client-side image cropping and conversion! ...