1
Я использую HTML5 Перетащите & Загрузите файл с помощью C# asp.net. Во всех браузерах все работает нормально, но в IE10 я не могу получить файлы на сервере, чтобы их сохранить. Я пробовал все, и ничего не работает. прошу помочь.Request.Files пуст только в ie10 с помощью xmlHttpRequst и ashx
вот мой код:
Javascript & HTML:
function uploadFile(index) {
var files = window.opener.files; //get the files from drag area which is in window.opener
for (var i = index; i < (index + files.length); i++) {
debugger;
var size = fixSize(files.item(i - index).size);
var name = files.item(i - index).name;
xhr.push(new XMLHttpRequest()); //create new xhr and push it to xhr array
//var form = window.opener.document.getElementById('ddform');
//var data = new FormData(form);
var data = new FormData();
data.append("index", i);
data.append("fileName", name);
data.append("file", files.item(i - index));
xhr[i].open('POST', "HandlerUploadFiles.ashx", true);
xhr[i].send(data);
}
}
ddform в открывающего окно:
<form id="ddForm" enctype="multipart/form-data" >
<div id="drop_zone">
<asp:Label ID="lblDragDrop" runat="server" Text="Drag File" style="color: #9A9A9A" ClientIDMode="Static"></asp:Label>
</div>
<asp:Button ID='btnRefresh' runat="server" onclick="btnRefresh_Click" style="display:none" />
</form>
C#, используя IHttpHandler:
public class HandlerUploadFiles : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
// context.Response.ContentType = "text/plain";
string fileName = context.Request["fileName"];
string postedFile = context.Request["file"]; // returns string : {"object file"}
HttpFileCollection fileCollection = context.Request.Files; // always empty!!!
...
}
}
Я заметил, что при использовании IE10 или последнего хрома или ff в файле 'context.Request.Files' есть 0 ключей, но когда вы смотрите в' context.Request', длина содержимого есть. Я сам не знаю, как получить файл (ы) оттуда. Но в IE9 и ниже и других старых браузерах 'context.Request.Files' имеет длину 1+ – Pierre
Почему вы отправляете каждый файл в свой собственный XHR? Просто добавьте все файлы к экземпляру 'FormData' в for-loop, а затем отправьте только один XHR. – idbehold