Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i check number of files selected with Fine Uploader?

I am using manual uploading via Fine Uploader. Now i want to check that file has selected or not.

$(document).ready(function() {
    var fineuploader = new qq.FineUploader({
        element: $('#fine-uploader')[0],
        request: {
            endpoint: '<?php echo site_url('pl_items/upload_images');?>'
        },
        multiple: true,
        autoUpload: false,
        onLeave: false,
        validation: {
            allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
            sizeLimit: 5120000 // 50 kB = 50 * 1024 bytes
        },
        text: { 
            uploadButton: '<i class="icon-plus icon-white"></i> Select Files' 
        },
        template: '<div class="qq-uploader">' +
                  '<pre class="qq-upload-drop-area"><span>{dragZoneText}</span></pre>' +
                  '<div class="qq-upload-button btn btn-danger">{uploadButtonText}</div>' +
                  '<div class="qq-drop-processing span1"><span>{dropProcessingText}</span><span class="qq-drop-processing-spinner"></span></div>' +
                  '<div><ul class="qq-upload-list"></ul></div>' +
                   '</div>',
        callbacks: {
            onComplete: function(id, name, response) {
                $('#frmDetails').append('<input type="hidden" name="pl_item_images[]" value="'+response.file_name+'">');
                //$("#frmDetails").submit();
            }
        },
    });

    $('#submit_button').click(function() {
        fineuploader.uploadStoredFiles();
    });
});
like image 791
Raju Singh Avatar asked Jun 18 '13 18:06

Raju Singh


1 Answers

Since you haven't responded to my question, I'll just assume that you want to determine if a file has been selected before you call uploadStoredFiles in your click handler.

It's really very simple. Just make use of the getUploads API method. For example, you could change your click handler to look like this:

$('#submit_button').click(function() {
    var submittedFileCount = fineuploader.getUploads({status: qq.status.SUBMITTED}).length;

    if (submittedFileCouunt > 0) {
        fineuploader.uploadStoredFiles();
    }
});

A few more things:

  • There is no onLeave option. You should remove this from your code.
  • The multiple option defaults to true. You can remove this from your code as well.
  • You are already using jQuery. Why aren't you using the Fine Uploader jQuery plug-in? See the documentation for instructions.
like image 77
Ray Nicholus Avatar answered Nov 18 '22 17:11

Ray Nicholus