Skip to content

Commit

Permalink
Fix uploading same file twice in a row in Chromium
Browse files Browse the repository at this point in the history
To upload files a hidden file input is "clicked", which shows the
browser dialog to pick the files, and the "change" event of the file
input is listened to to know the selected files.

However, although Firefox always emits the "change" event when files are
selected, Chromium only emits the "change" event if the selected files
have changed since the last time. Due to this if a file was uploaded and
then the same file was tried to be uploaded again nothing happened.

Now the value of the file input is cleared (which also clears the files
from the file input) after the files are handled to ensure that there is
no previous state when the browser dialog is shown again, and thus the
selected files always change.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
danxuliu committed Nov 6, 2020
1 parent 36617f6 commit 40765c3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/NewMessageForm/NewMessageForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ export default {
const files = Object.values(event.target.files)

this.handleFiles(files)

// Clear input to ensure that the change event will be emitted if
// the same file is picked again.
event.target.value = ''
},

/**
Expand Down

0 comments on commit 40765c3

Please sign in to comment.