Search code examples
javascriptfine-uploader

Clear File List in Fine Uploader in purpose to reupload just one file


I use fine uploader to upload just one file on 'edit entity' page. Entity should have one file assosiated with it. I should show user a popup message with error if he selects more than 1 file in file browser while uploading. I want to set limit to fineUploader and use this setting:

itemLimit: 1

The issue is that if I load one first file it works ok, but if I try to reload it I have validation error (I have my own code for UI that clears control(link) with uploaded file and writes new link there). I know that error appiars because there is a fileList inside Fine Uploader and for it I upload - not reload - another file.

I tryed some code to clear fine uploader state. For example:

onComplete: function (id) {
                    qq(this.getItemByFileId(id)).remove();
                },

But it works only for UI elements, not for "inside" data. Actually, after several hours googling this issue it seems to me that my problem doesn't have any solution, but probably someone knows...


Solution

  • ok, so, I found the answer. The function that helped me is reset(); It resets the state of fine uploader and file list, sure, also. Now I have validation for case if user select several files for upload in file browser and at the same time I don't have any erros while uploading ONE file several times. Here is my version of 'onAllComplete' event.

    onAllComplete: function (succeeded, failed) {
                        //some code that saves file on the server
                        this.reset(); // the fix
                    },