我正在尝试通过jQuery文件上传(http://blueimp.github.io/jQuery-File-Upload/)将文件上传到服务器端。我的客户如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="js/jquery-1.11.2.min.js" type="text/javascript"></script>
<script src="js/jquery-widget.js" type="text/javascript"></script>
<script src="js/jquery.iframe-transport.js" type="text/javascript"></script>
<script src="js/jquery.fileupload.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#fileupload').fileupload({
url: 'attachmentsHandler.ashx',
replaceFileInput: false,
dataType: 'json',
done: function (e, data) {
$.each(data.result, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
},
add: function (e, data) {
data.submit();
}
});
});
在服务器端,我有一个简单的处理程序,代码如下:
using System;
using System.Web;
using System.IO;
public class attachmentsHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
//context.Response.ContentType = "text/plain";
string path = context.Server.MapPath("~/attachments");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
var file = context.Request.Files[0];
string fileName = Path.Combine(path + file.FileName);
file.SaveAs(fileName);
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var result = new { name = fileName };
context.Response.Write(serializer.Serialize(result));
}
public bool IsReusable {
get {
return false;
}
}
}
我在评估context.Request.Files时遇到超时。