FineUploader作为一个请求上传多个文件 [英] FineUploader uploading multiple files as one request

查看:42
本文介绍了FineUploader作为一个请求上传多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个请求,我需要上传多个文件. 例如,我有两个需要保存的必需文件(.csv和.ctl). 基本上在服务器端,我正在读取.csv文件,并对照.ctl文件进行检查.如果某些条件不匹配,则无需上传.我不确定如何或需要更新上传"方法以读取文件名[].我也不需要更新此行"uploader.fineUploader('uploadStoredFiles');"现在,用户单击立即上传"即可接受文件名[].

I need to upload multiple files as one request. For example, i have two required files (.csv & .ctl) that I need to save. Basically on the server side, I'm reading the .csv file and checking it against the .ctl file. If certain criteria doesn't match, I don't need to upload it. I'm not sure how or need to update the 'upload' method to read the filenames[]. Nor if I need to update this line "uploader.fineUploader('uploadStoredFiles');" to now accept the filenames[] after the user clicks "Upload now."

<script type="text/javascript">
    $(document).ready(function () {
        var filenames = [];
        var uploader = $("#fine-uploader").fineUploader({
            request: {
                endpoint: '<%= ResolveUrl("~/Handler/UploadHandler.ashx")%>'
            },
            autoUpload: false,
            text: {
                uploadButton: '<span class="glyphicon glyphicon-plus"></span> Select Files'
            },
            validation: {
                allowedExtensions: ['csv', 'ctl']
            },
            showMessage: function (message) {
                // Using Bootstrap's classes
                $('#fine-uploader').append('<div class="alert alert-danger">' + message + '</div>');
            }
        }).on('validate', function (event, fileData) {
            return $.inArray(fileData.name, filenames) < 0;
        }).on('submitted', function (event, fileId, fileName) {
            filenames.push(fileName);
        }).on('upload', function (event, fileId, fileName) {
            var fileItemContainer = $(this).fineUploader('getItemByFileId', fileId);
            $(this).fineUploader('setParams', { uploadType: 'VendorFileType', vendorId: '<%=vendorDropdownList1.CurrentVendorID %>' }, fileId);
        }).on('complete', function (event, fileName, fileName, responseJSON) {
            if (responseJSON.success) {
                var div = document.getElementById('fine-uploader-status');
                div.innerHTML = 'Upload process complete.';
            }
            else {
                var div = document.getElementById('fine-uploader-status');
                div.innerHTML = 'Upload denied.';

            }
        });

        $('#uploadSelectedFiles').click(function () {
            uploader.fineUploader('uploadStoredFiles');
        });
    });
</script>

 //here's the aspx side.
<div id="fine-uploader">
</div>
<div id="fine-uploader-status">
</div>
<button id="uploadSelectedFiles" class="btn btn-primary">
    <span class="glyphicon glyphicon-upload"></span>Upload now</button>

推荐答案

Fine Uploader不支持在单个请求中发送多个文件.这不必要地使代码复杂化,并且会破坏某些现有功能.每个文件在单独的请求中发送.您说您正在执行一些服务器端检查以防止上载,但是到服务器无论如何都可以执行这些比较时,文件已经被上载了.从您的问题尚不清楚,为什么您需要在一个请求中上传多个文件,或者这样做有什么好处.如果您澄清,也许我可以提供其他建议.

Fine Uploader does not support sending multiple files in a single request. This complicates the code unnecessarily and would break some existing features. Each file is sent in a separate request. You say you are performing some server-side checks to prevent uploads, but the files have already been uploaded by the time your server is able to perform these comparisons anyway. It's not clear from your question why you need to upload multiple files in a single request, or what benefit this gives you. If you clarify, perhaps I can provide alternate suggestions.

这篇关于FineUploader作为一个请求上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆