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

1

7

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();
    });
});
Backed answered 18/6, 2013 at 18:5 Comment(2)
Where do you want to check the number of selected files, and why?Vouvray
Well I have come across the same problem ! Is it possible to know the total number of images selected and they are rendered/loaded in the preview box (either preview is available or not) ! I want to disable the upload button until all the images are loaded correctly.Elfont
V
11

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.
Vouvray answered 20/6, 2013 at 2:35 Comment(5)
If this solved your problem, please consider accepting my answer.Vouvray
I'm not that user though hehe, I upvoted you answer, but that's all I can do hehe. Hey any reason why my "qq" variable would not have a .STATUS?Nitroso
@SébastienRicher Yes. The most likely cause is you are using a version of Fine Uploader older than 3.6. Also, the property is status, and not STATUS.Vouvray
Your code will not work. You have a typo error in variable name "submittedFileCouunt". :P... anyway good answer.Pasteup
In my case, there is no form submit button, i have a browse button functionality which uploads selected files then how can i get number of files before starting uploading process? Please suggest me. Thank you.Yonah

© 2022 - 2024 — McMap. All rights reserved.