.upload() uploads all files, not just one
JasonWilliamsIG opened this issue · 0 comments
I wanted to be able to add a list of existing files in a folder into the queue - which I've done, but they're dummy, with no file contents, just details and showing as uploaded at 100% (they will be accepted prior to any browser close/session expiry).
For example, I have two files which are already in a folder, which my .net core WebAPI returns the data regarding the file and then adds it into the queue. When I then try to upload a new file, the new one will upload and the previous will show as an error, as they're attempting to re-upload again - when I don't need to them.
So I thought I'd use the .upload() option, by looping through the files in the queue and if it is showing as not uploaded (IE the new file), then upload that file only, but when triggering this in a for loop, it attempts to upload all files - hence why I get the error above.
My understanding was that .upload() would only upload the file referenced, not all the files.
Or am I missing something?
Here is the block of code handling the onAfterAddingFile:
this.uploader.onAfterAddingFile = (fileItem: FileItem) => {
let fileExists = this.uploader.queue.filter(x => x.file.name == fileItem.file.name).length;
if (fileExists >= 2) {
this.response = `<strong>${fileItem.file.name}</strong> already exists in the temporary upload location,
please delete the previous file if you want upload the new file.`
fileItem.isError = true;
fileItem.isUploaded = true;
} else {
this.singleFile = {
name: fileItem.file.name,
isError: false,
isSuccess: false
};
// This checks whether the file exists in the upload location
this.api.checkSFTPFiles(this.singleFile).subscribe((res) => {
if (res.message != 'OK') {
this.response = `<strong>${fileItem.file.name}</strong> already exists in the upload location.</a>`
fileItem.isError = true;
fileItem.isUploaded = true;
} else {
// How do we handle this?
let queue = this.uploader.queue;
for (var i = 0; i < queue.length; i++) {
if (!queue[i].isUploaded) {
queue[i].upload();
}
}
}
});
}
}