Topic: beforeupload event

hello ,
i use beforeUpload  event to check some extras parmeters (in multipart_params). My probleme is that when i have found an unexecpted parameter,  I return false to advoid upload. But after i can not click again on upload button , nothing is coming. I haved tryed to use refresh method but no success.

there is a way to validate parameter in beforeUpload and after bind again the upload button?

thank

Re: beforeupload event

Are you using one of the widgets? Post your config.

If you want to see your issue fixed, do not report it here, do it on - GitHub.

Re: beforeupload event

i have find a way , but i'm stuck in the middle ;-)
when i return false in beforeUpload method the trigger("UploadFile", file) in the function uploadNext() (private methode of uploader) is not fire, so i thinked that i can call it manually in my beforeupload method lik this :
file.status = plupload.UPLOADING;
up.trigger("UploadFile", file);

but if my condition is ok , the methode is trigger twice and two upload are started, i have tried to unbind and after bind to avoid twice caller , the unbind work well, but bind the event failed because the up.onUploadFile is private. my code below :

 uploader = new plupload.Uploader({
                        runtimes : 'html5',
     
                        browse_button : 'pickfiles', // you can pass in id...
                        container: document.getElementById('container'), // ... or DOM Element itself
     
                        url : "{{ oneup_uploader_endpoint('gallery') }}",
                        
                        chunk_size: '10mb',
                        multi_selection : false,
                        filters : {
                            max_file_size : '100000000mb',
                            mime_types: [
                                {title : "Zip files", extensions : "zip"},
                                {title : "PDF files", extensions : "pdf"}
                            ]
                        },
                        multipart_params : {
                                "destination" : $("#destination").val(),
                                "produit" : $("#produit").val(),
                                "doctype" : $("#doctype").val()
                        },

                        init: {
                            PostInit: function() {
                                document.getElementById('filelist').innerHTML = '';
                                document.getElementById('uploadfiles').onclick = function() {
                                    uploader.start();
                                    return false;
                                };
                            },
                            BeforeUpload: function (up, file) {
                                
                                
                                var destination = up.settings.multipart_params.destination;
                                var docType = up.settings.multipart_params.doctype;
                                
                                
                                console.log("destination :",destination);
                                console.log("doctype :",docType);
                                console.log("produit : ",produit);
                                if(destination == null || doctype == null) return false;
                                
                             
                                
                                up.unbind('UploadFile', up.onUploadFile);

                                file.status = plupload.UPLOADING;
                                up.bind('UploadFile', up.onUploadFile);
                                up.trigger("UploadFile", file);
 
                            },

                            FilesAdded: function(up, files) {
                            
                                    console.log("file added event :",files)
                                    var fileCount = up.files.length,
                                    i = 0,
                                    ids = $.map(up.files, function (item) { return item.id; });

                                    for (i = 0; i < fileCount-1; i++) {
                                        console.log("for each ")
                                        uploader.removeFile(uploader.getFile(ids[i]));
                                    }
                                    
                                    $("#filelist").empty();
                                    
                                    plupload.each(files, function(file) {
                                        document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
                                    });
                                    
                                    
                            },
                            
                            UploadProgress: function(up, file) {
                                $("#jqxProgressBar").jqxProgressBar({ value: file.percent });
                                document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
                            },
                            UploadComplete : function(up,file){
                                console.log("complete")
                            },
                            Error: function(up, err) {
                                console.log(err);
                                document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
                            }
                        }
                    });

                    uploader.init();

thank

Re: beforeupload event

i hav found a way for any check before upload. plUpload give me what i need, i use custom filters and it's awesome.

plupload.addFileFilter let you check before files are added to list.

thank