jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 使用chunking进行程序化文件上传:仅发送第一个文件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当使用 jQuery-File-Upload plugin使用分块启用的 programmatic file upload时,无法获取多个文件发送.

我打电话如下:

fileUploadWidget.fileupload('send',{
    files: filesList
})

filesList是File对象的列表.

另外我已经设置了maxChunkSize,并将singleFileUploads设置为true(我也尝试过falsE),如Options wiki page所示.

有没有人有这样的工作成功?

更新:

我在GitHub上做了一个issue这个问题,这里是作者的回应:

我们的解决方

正如已经评论过的那样,我们最终做的是将文件发送到一个循环,在这个循环中,widget被初始化为sequentialUploads设置为true(你会想要这个取决于你的后端如何配置):

// for illustration only
// does not do anything with the returned jqXHR objects
for (i = 0; i < files.length; i++) {
    widget.fileupload('send',{ files: files[i] });
}

解决方法

如果你使用C#作为后端,你可以试试这个(Client-Side,JQuery):
$("#btnUpload").click(function () { // btnUpload is the ID of any button for upload
            var formdata = new FormData(); //FormData object
            var fileInput = document.getElementById('fileInput');
            //Iterating through each files SELEcted in fileInput
            for (i = 0; i < fileInput.files.length; i++) {
                //Appending each file to FormData object
                formdata.append(fileInput.files[i].name,fileInput.files[i]);
            }
            //CreaTing an XMLhttprequest and sending
            var xhr = new XMLhttprequest();
            xhr.open('POST','/UploadMethod'); // UploadMethod is your BACk-end code
            xhr.send(formdata);
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    // alert("uploaded");
                    }
            }

        });

然后在你UploadMethod上这样做:(ServerSide,C#)

public void Upload()
        {
            for (int i = 0; i < request.Files.Count; i++)
            {
                httpPostedFileBase file = request.Files[i]; //Uploaded file
                //Use the following properties to get file's name,size and MIMEType
                int fileSize = file.ContentLength;
                String filename = file.Filename;
                String mimeType = file.ContentType;
                System.IO.Stream fileContent = file.InputStream;
                //To save file,use SaveAs method
                var appPath = HosTingEnvironment.ApplicationPhysicalPath + "Documents/" + "_" +  datetiR_577_11845@e.Now+ filename;

                file.SaveAs(appPath); //File will be saved in Documents folder
              }
        }

大佬总结

以上是大佬教程为你收集整理的jquery – 使用chunking进行程序化文件上传:仅发送第一个文件全部内容,希望文章能够帮你解决jquery – 使用chunking进行程序化文件上传:仅发送第一个文件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。