Select a local image in Cocos Creator Web with a hidden file input, read or compress Base64 data, create Texture2D and SpriteFrame assets, upload it, and clean up DOM events.
Cocos Creator version: 3.7.2.
A web game or app may need to let users upload a local image for an avatar or preview. Cocos Creator does not provide a native browser file picker, so this implementation combines an HTML <input type="file"> with TypeScript.
FileReader converts the selected image into a Base64 data URL. Large images may fail to upload, so this example compresses them first. Compression is optional.
Always remove the input when the component is destroyed. Otherwise document.body and the event listener continue referencing it, preventing garbage collection and potentially causing unexpected behavior later.