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

change file problem #649

Closed
rqx110 opened this issue Jun 29, 2016 · 6 comments
Closed

change file problem #649

rqx110 opened this issue Jun 29, 2016 · 6 comments

Comments

@rqx110
Copy link

rqx110 commented Jun 29, 2016

follow step:

  1. config the upload: queueLimit=1,autoUpload=false
  2. select file "1.png" (have not upload yet)
  3. select file "2.png" (that is what i want to upload)
  4. upload the select file. It's strange that the uploaded file is "1.png" not the "2.png"

Is it a bug? or not please give me a solution.

@nervgh
Copy link
Owner

nervgh commented Jul 5, 2016

When files are selected or dropped into the component, one or more filters are applied. Files which pass all filters are added to the queue. When file is added to the queue, for him is created instance of {FileItem} and uploader options are copied into this object. After, items in the queue (FileItems) are ready for uploading.
https://github.com/nervgh/angular-file-upload#about

Insert these lines into your code for undestanding

uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/, filter, options) {
    console.info('onWhenAddingFileFailed', item, filter, options);
};
uploader.onAfterAddingFile = function(fileItem) {
    console.info('onAfterAddingFile', fileItem);
};

https://github.com/nervgh/angular-file-upload/blob/v2.3.4/examples/simple/controllers.js#L26

See also https://github.com/nervgh/angular-file-upload/wiki/FAQ#4-no-file-chosen-or-re-add-same-file

@Velius5
Copy link

Velius5 commented Aug 18, 2016

I had the same problem with single file uploading.
My solution:

uploader.onWhenAddingFileFailed  = function(item, filter, options) {
    if(filter.name == "queueLimit") {
        uploader.clearQueue();
        uploader.addToQueue(item);
    }
}

@CodemonkeyTim
Copy link

CodemonkeyTim commented Sep 20, 2016

I had the same problem and tried the solution by Velius5. Unfortunately it didn't work with canvas image preview so what I ended up doing was removing the queueLimit filter and adding this event callback:

uploader.onAfterAddingFile = function(item, filter, options) {
   if (uploader.queue.length > 1) {
      uploader.queue.splice(0, 1);
    }
};

@arrowing
Copy link

arrowing commented Nov 25, 2016

@Velius5 I just use same solution.
But it doesn't work at fact.
Because the item variable is FileItem(FileLikeObject type), not {FileList|File|HTMLInputElement} type.
But the "addToQueue" method need {FileList|File|HTMLInputElement} type.
So it doesn't work when I upload. Some data from file are lost.

@arrowing
Copy link

@CodemonkeyTim Nice job!

@gerome0123
Copy link

@Velius5 i try your solution but i got rollback in my server file_fingerprint is NULL

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

6 participants