Select a photo, simulate a failed upload, and select the same photo again. If the input still holds that file, the browser can treat the second selection as a cancellation, so a change handler may never run.
For a JavaScript-managed queue, take a reference to the File before clearing the picker. In this example addPhotoToQueue is the application function that stores the file.
<label for = "photo" > Add a photo </label> <input id = "photo" type = "file" accept = "image/*" >
Enter fullscreen mode
Exit fullscreen mode
const picker = document . querySelector ( "#photo" ) ; picker . addEventListener ( "change" , ( ) => { const file = picker . files [ 0 ] ; if ( ! file ) return ; picker . value = "" ; addPhotoToQueue ( file ) ; } ) ;
Enter fullscreen mode
Exit fullscreen mode
Show the filename from the queue once the picker resets.…