Select a local image in a Cocos Creator web build, convert it to Base64, display it as a sprite, and clean up the DOM input.
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.