gpt4 book ai didi

asp.net-mvc - dropzonejs 多文件上传无法按预期工作

转载 作者:可可西里 更新时间:2023-11-01 16:38:15 26 4
gpt4 key购买 nike

我正在尝试使用多重上传,但在我的 MVC 操作中,我没有获得上传文件的列表,而是获得每个上传项目的文件 []。

我正在上传 2 个文件,但是当我通过以下方式在我的 Controller 中访问它时:

        foreach (string filename in Request.Files)
{
var file = Request.Files[filename];
//file.name always reads from file[] and picks the first file in all requests


}

我的完整请求是:

Request URL: http://localhost:54434/1328/uploads/new
Request Method:POST
Status Code:201 Created
Request Headersview source
Accept:application/json
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:8957136
Content-Type:multipart/form-data; boundary=----WebKitFormBoundarysX8tBB9TH4BzWZsG
Cookie:glimpsePolicy=On; _gauges_unique_month=1; _gauges_unique_year=1; _gauges_unique=1; glimpseId=Chrome 28.0; __RequestVerificationToken=itQ6HqqB_D7H_Y924w-HFfF8tq
ASP.NET_SessionId=cnj4lzpunuxnbyunl1m5gtpn
Glimpse-Parent-RequestID:04a1b6d2-6c6a-4da0-936d-3ff39e5b8c6c
Host:localhost:54434
Origin:http://localhost:54434
Referer:http://localhost:54434/1328/uploads/new
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payload
------WebKitFormBoundarysX8tBB9TH4BzWZsG
Content-Disposition: form-data; name="__RequestVerificationToken"

dmPL-YRqsiwjKy43rlkYIBJE4kPlthsyL0IgnyHbtrD7Doczpbu9Z1SYeoL_93vuR15-6HfpNCCEzkzLYHBIxFJOQd3ynRGGYqILGpMWdLE1
------WebKitFormBoundarysX8tBB9TH4BzWZsG
Content-Disposition: form-data; name="private_upload"

true
------WebKitFormBoundarysX8tBB9TH4BzWZsG
Content-Disposition: form-data; name="files[]"; filename="Maid with the Flaxen Hair.mp3"
Content-Type: audio/mp3


------WebKitFormBoundarysX8tBB9TH4BzWZsG
Content-Disposition: form-data; name="files[]"; filename="Sleep Away.mp3"
Content-Type: audio/mp3


------WebKitFormBoundarysX8tBB9TH4BzWZsG--
Response Headersview source
Cache-Control:private, s-maxage=0
Content-Encoding:gzip
Content-Length:57
Content-Type:application/json; charset=utf-8
Date:Fri, 16 Aug 2013 10:55:23 GMT
Server:Microsoft-IIS/8.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:4.0
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?QzpcUHJvamVjdHNcU3VydmVudHJpeFxhcHBcU3VydmVudHJpeFxGYXN0U3VydmV5b3JzXDEzMjhcdXBsb2Fkc1xuZXc=?=

````

Dropzone 配置是:

<script type="text/javascript">
Dropzone.autoDiscover = false;

var myDropzone = new Dropzone("form#my-awesome-dropzone", {
paramName: "files", // The name that will be used to transfer the file
autoProcessQueue: false,
forceFallback: false,
uploadMultiple: true,
maxFilesize: 10,
previewsContainer: ".dropzone-previews",
clickable: ".dropzone" //make only this region clickable
});

myDropzone.on("addedfile", function (file) {
/* Maybe display some more file information on your page */
console.debug("added a file: " + file.name);
});

myDropzone.on("success", function (file) {
$("#drop-success").show();
});

$("#btnDropzone").click(function () {
myDropzone.processQueue();
});
});
</script>

如何在我的 Controller 中获取每个上传的文件以便我可以处理它?<​​/h3>

最佳答案

如果输入名称 file[] 确实是问题所在,那么您可以将 Dropzone 选项 uploadMultiple 设置为 false。这将创建多个请求并单独发送每个文件,而不是在一个请求中发送所有并行上传的文件。

关于asp.net-mvc - dropzonejs 多文件上传无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18272703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com