仅一两个文件上传到服务器

发布于 2025-01-12 21:44:43 字数 5119 浏览 2 评论 0原文

我正在使用 Dropzone 并行上传六个文件;它在本地运行良好(本地主机)。但相同的代码在 QA 环境中无法按预期工作。当我尝试上传六个文件时,它会在服务器上上传一两个文件。我不明白问题出在哪里。这是我的客户端代码(index.chtml):

    var myDropzone = new Dropzone("#dropzoneJsForm", {
    
            autoProcessQueue: false,
            uploadMultiple: true,
            parallelUploads: 10,
            maxFiles: 6,
            maxFilesize: 3,
            acceptedFiles: ".pdf",
            addRemoveLinks: true,
            init: function () {
             
          
                this.on('sendingmultiple', function (data, xhr, formData) {
                    // this will get sent
                    formData.append('customerID', jQuery('#CustomerId').val());
                    formData.append('RecordId', @Model.Id);
                    formData.append('VIN', jQuery('#TransactionVIN').val());
                    formData.append('DateReceived', jQuery('#CreatedOn').val());
                 });
                this.on("complete", function (file) {
                    if (file.size > 3.0 * 1024 * 1024) {
                        this.removeFile(file);
                        alert('File was Larger than 3.0Mb!');
                        return false;
                    }
    
                    if (!file.type.match('pdf.*')) {
                        this.removeFile(file);
                        alert('Upload PDF Only!')
                        return false;
                    }
                    if (!file.type.match('pdf.*')) {
                        this.removeFile(file);
                        alert('Upload PDF Only!')
                        return false;
                    }
                 
                    if (this.files.length > this.options.maxFiles) {
                        this.removeFile(file);
                        alert('Maximum six files are allowed to upload!')
                        return false;
                    }
                });
                   this.on("queuecomplete", function () {
                    this.options.autoProcessQueue = false;
                });
    
                this.on("processing", function () {
                    this.options.autoProcessQueue = true;
                });
    
            },
            success: function (file, response) {
                var imgName = response;
                file.previewElement.classList.add("dz-success");
    
            },
            error: function (file, response) {
                file.previewElement.classList.add("dz-error");
            }
    
        });
         
        $('#submit-all').click(function (e) {
            e.preventDefault();
            e.stopPropagation();
            showSpinner();
            $('#submit-all').attr('disabled', true);
            $('#submit-cancel').attr('disabled', true);
           if (myDropzone.getQueuedFiles().length > 0) {
                myDropzone.options.autoProcessQueue = true;
                  myDropzone.processQueue();
               }
           else {
               myDropzone.uploadFiles([]);
               $("#dropzoneJsForm").submit();
            }
          
        });
    
    })

Code at Controller:

    foreach (string fileName in request.Files)
    {
    HttpPostedFileBase file = request.Files[fileName];
    
                            fileNames.Add(file.FileName);
                            string _path="";
                            // save file as required here...
                            if (file != null && file.ContentLength > 0)
                            {
    
                                string fName = file.FileName;
                                string extension = fName.Substring(fName.Length - 4);
    
                                string fNameWithoutExtension = fName.Substring(0, fName.Length - 4);
                                fName = fNameWithoutExtension;
                                fNameWithoutExtension = fNameWithoutExtension + strTransactionID + myDateTimeStamp;
                                string newFileName = fNameWithoutExtension + extension;
    
                                 _path = Path.Combine(location, newFileName);
    
                                //Create the directory if it doesn't exist
                                System.IO.FileInfo fileInfo = new System.IO.FileInfo(_path);
                                fileInfo.Directory.Create();
    
                                file.SaveAs(_path);
                                var proxySub = ctx.CustomerDocumentsList.Create();
                                proxySub.CustomerDocumentsId = RecordId;
                                proxySub.UploadedFileName = fName;
                                proxySub.UploadedFileNameWithPath = _path;
                                proxySub.DeleteFlag = 0;
                                ctx.CustomerDocumentsList.Add(proxySub);
                                
                                logger.WriteLog("Record Inserted for: " + fName);
                           
                        }
    
                    }

我已经花了很多时间,但还没有运气。请帮助我并让我知道问题出在哪里。预先非常感谢。

I am using Dropzone to upload six files in parallel; it works fine locally (localhost). But the same code does not work as expected on QA environment. It uploads one or two files on server when I try to upload six files. I don't understand where is the problem. Here is my code for client side (index.chtml):

    var myDropzone = new Dropzone("#dropzoneJsForm", {
    
            autoProcessQueue: false,
            uploadMultiple: true,
            parallelUploads: 10,
            maxFiles: 6,
            maxFilesize: 3,
            acceptedFiles: ".pdf",
            addRemoveLinks: true,
            init: function () {
             
          
                this.on('sendingmultiple', function (data, xhr, formData) {
                    // this will get sent
                    formData.append('customerID', jQuery('#CustomerId').val());
                    formData.append('RecordId', @Model.Id);
                    formData.append('VIN', jQuery('#TransactionVIN').val());
                    formData.append('DateReceived', jQuery('#CreatedOn').val());
                 });
                this.on("complete", function (file) {
                    if (file.size > 3.0 * 1024 * 1024) {
                        this.removeFile(file);
                        alert('File was Larger than 3.0Mb!');
                        return false;
                    }
    
                    if (!file.type.match('pdf.*')) {
                        this.removeFile(file);
                        alert('Upload PDF Only!')
                        return false;
                    }
                    if (!file.type.match('pdf.*')) {
                        this.removeFile(file);
                        alert('Upload PDF Only!')
                        return false;
                    }
                 
                    if (this.files.length > this.options.maxFiles) {
                        this.removeFile(file);
                        alert('Maximum six files are allowed to upload!')
                        return false;
                    }
                });
                   this.on("queuecomplete", function () {
                    this.options.autoProcessQueue = false;
                });
    
                this.on("processing", function () {
                    this.options.autoProcessQueue = true;
                });
    
            },
            success: function (file, response) {
                var imgName = response;
                file.previewElement.classList.add("dz-success");
    
            },
            error: function (file, response) {
                file.previewElement.classList.add("dz-error");
            }
    
        });
         
        $('#submit-all').click(function (e) {
            e.preventDefault();
            e.stopPropagation();
            showSpinner();
            $('#submit-all').attr('disabled', true);
            $('#submit-cancel').attr('disabled', true);
           if (myDropzone.getQueuedFiles().length > 0) {
                myDropzone.options.autoProcessQueue = true;
                  myDropzone.processQueue();
               }
           else {
               myDropzone.uploadFiles([]);
               $("#dropzoneJsForm").submit();
            }
          
        });
    
    })

Code at Controller:

    foreach (string fileName in request.Files)
    {
    HttpPostedFileBase file = request.Files[fileName];
    
                            fileNames.Add(file.FileName);
                            string _path="";
                            // save file as required here...
                            if (file != null && file.ContentLength > 0)
                            {
    
                                string fName = file.FileName;
                                string extension = fName.Substring(fName.Length - 4);
    
                                string fNameWithoutExtension = fName.Substring(0, fName.Length - 4);
                                fName = fNameWithoutExtension;
                                fNameWithoutExtension = fNameWithoutExtension + strTransactionID + myDateTimeStamp;
                                string newFileName = fNameWithoutExtension + extension;
    
                                 _path = Path.Combine(location, newFileName);
    
                                //Create the directory if it doesn't exist
                                System.IO.FileInfo fileInfo = new System.IO.FileInfo(_path);
                                fileInfo.Directory.Create();
    
                                file.SaveAs(_path);
                                var proxySub = ctx.CustomerDocumentsList.Create();
                                proxySub.CustomerDocumentsId = RecordId;
                                proxySub.UploadedFileName = fName;
                                proxySub.UploadedFileNameWithPath = _path;
                                proxySub.DeleteFlag = 0;
                                ctx.CustomerDocumentsList.Add(proxySub);
                                
                                logger.WriteLog("Record Inserted for: " + fName);
                           
                        }
    
                    }

I have spent a good amount of time but no luck yet. Please assist me and let me know where is problem. Thanks a lot in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文