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

.upload() uploads all files, not just one #1262

Open
JasonWilliamsIG opened this issue Sep 11, 2023 · 0 comments
Open

.upload() uploads all files, not just one #1262

JasonWilliamsIG opened this issue Sep 11, 2023 · 0 comments

Comments

@JasonWilliamsIG
Copy link

JasonWilliamsIG commented Sep 11, 2023

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();
          }
        }
      }
    });        
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant