1

我在 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');
4

1 回答 1

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
    }
}

Github 上也有一个未解决的问题引用了这个问题。一个潜在的解决方案计划在下一个版本中发布。

于 2013-06-05T16:46:42.057 回答