4

I'm using the plugin qq.FileUploader.

Before submitting file, I want to know if a file with the same name has already been upload.

I'm using this code:

var uploader = new qq.FileUploader({
        element: document.getElementById('file-uploader-requestDocuments'),
        action: '<%: Url.Action("Create", "RequestDocument") %>',
        params: { id: $('#RequestTempUploadFolderID').val() },
        sizeLimit: 10520000,
        onSubmit: function (id, fileName)
            $('#file-uploader-requestDocuments').find('.qq-upload-file').each(function () {
                if ($(this).text() == fileName) {
                    return false;
                return true;
            });
        }
    });

The return false is correct, but it does not stop the submit!

How stop the file upload, and there is a better way to get the file already uploaded?

Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
FRO
  • 253
  • 1
  • 7
  • 17

1 Answers1

5

how about doing that checking in your server side?! and returning a response in AJAX, for duplicate file names?!

EDIT

if your server response this:

{"success":"false", "errorMessage":"File name is duplicate!"}

you can have that JS code:

var uploader = new qq.FileUploader({
        element: document.getElementById('file-uploader-requestDocuments'),
        action: '<%: Url.Action("Create", "RequestDocument") %>',
        params: { id: $('#RequestTempUploadFolderID').val() },
        sizeLimit: 10520000,
        onComplete: function(id, fileName, responseJSON){
            if(!responseJSON.success){alert(responseJSON.errorMessage);}
        }
    });
Arthur Neves
  • 11,840
  • 8
  • 60
  • 73
  • Yes it's better. So now, why the function showMessage: function(message){ alert(message); } is never called? – FRO Jun 22 '11 at 19:12
  • 1
    actually now the showMessage will be not call! you should use onComplete: function(id, fileName, responseJSON){}, then u can grab the responseJSON and display a message.(will edit my answer to add that code) – Arthur Neves Jun 22 '11 at 20:46
  • May I upload upto 5GB file on network storage server using this article? – dilipkumar1007 Apr 21 '14 at 06:34