fineUploader最小文件验证数

时间:2013-06-05 16:03:42

标签: jquery asp.net-mvc fine-uploader

我正在使用带有MVC 4的FineUploader,我意识到如果没有选择文件,fineUploader将不会发布,我想知道是否有用户上传至少一个文件的验证?以下是我使用fineUploader的方法。

// INITIALIZING FINEUPLOADER

manualUploader = $('#' + uploaderElementId).fineUploader({
        request: {
            endpoint: endPoint
        },
        multiple: false,
        autoUpload: false,
        validation: {
            allowedExtensions: allowedExtensions,
            sizeLimit: 20971520 // 50 kB = 50 * 1024 bytes
        },
        text: {
            uploadButton: 'Select file'
        }
    }).on('submit', function (id, fileName) {
        //do nothing
    }).on('complete', function (event, id, fileName, responseJSON) {
        if (responseJSON.success && responseJSON.fileId !== undefined) {
            if (isImage) {
                $(this).prepend('<img src="/Webservices/FileStream.ashx?mode=download&fileid=' + responseJSON.fileId + '" class="webinar-image" />');
            }
            else {
                $(this).prepend('<a href="/Webservices/FileStream.ashx?mode=download&fileid=' + responseJSON.fileId + '">Uploaded File</a>');
            }
        }
    }).on('error', function (xhr, id, name, errorReason) {
        self._onfailUpload(errorReason);
    }); //end INIT FINE UPLOADER

//POSTING FINEUPLOADER
manualUploader.fineUploader('setParams', {
    '__RequestVerificationToken': $("input[name='__RequestVerificationToken']").val(),
    "webinarId": data.webinarId,
    "fileType" : "Pdf"
});
manualUploader.fineUploader('uploadStoredFiles');

1 个答案:

答案 0 :(得分:4)

是的,有办法!

假设您有某种onClick事件处理程序......

function handleUploadStoredFilesClick() {
    // qq.status.SUBMITTED is the status reserved for files added 
    // to the uploader but not yet uploaded
    var storedFiles = $('#myuploader').fineUploader('getUploads', { status: qq.status.SUBMITTED }).length

    // Here we check if the number of storedFiles is greater than 0,
    if (storedFiles > 0) {
        $('#myuploader').fineUploader('uploadStoredFiles');
    }
    else {
        //alert user that there are no files to upload
    }
}

还有an open issue on Github引用此问题。可以在下一个版本中找到一个潜在的解决方案。