Raju Singh
Raju Singh

Reputation: 780

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();
    });
});

Upvotes: 7

Views: 4784

Answers (1)

Ray Nicholus
Ray Nicholus

Reputation: 19890

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.

Upvotes: 11

Related Questions