Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Incorrect Rejection of First Uploaded File #2274

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions src/dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,21 +782,37 @@ export default class Dropzone extends Emitter {
this.emit("addedfile", file);

this._enqueueThumbnail(file);

this.accept(file, (error) => {
if (error) {
const addFileWithValidation = async () => {
try {
await this.acceptFile(file);
resolve(); // Resolve the Promise when validation is successful
} catch (error) {
file.accepted = false;
this._errorProcessing([file], error); // Will set the file.status
} else {
file.accepted = true;
if (this.options.autoQueue) {
this.enqueueFile(file);
} // Will set .accepted = true
this._errorProcessing([file], error);
resolve(); // Resolve the Promise even if validation fails
} finally {
this._updateMaxFilesReachedClass();
}
this._updateMaxFilesReachedClass();
};

addFileWithValidation();
}

acceptFile(file) {
return new Promise((resolve, reject) => {
this.accept(file, (error) => {
if (error) {
reject(error);
} else {
file.accepted = true;
if (this.options.autoQueue) {
this.enqueueFile(file);
}
resolve();
}
});
});
}

// Wrapper for enqueueFile
enqueueFiles(files) {
for (let file of files) {
Expand Down