回答
您可以使用确切的演示文件,而无需使用先前评论中链接的.NET示例。将表单操作链接更改为指向您创建的handler.ashx文件。
因此,在index.html的形式,将该网址添加到您的行动创建的处理程序:
<form id="fileupload" action="GongosHandler.ashx" method="POST" enctype="multipart/form-data">
然后做一个基本的处理程序编码为以下几点:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";//"application/json";
var r = new System.Collections.Generic.List<ViewDataUploadFilesResult>();
for (var x = 0; x < context.Request.Files.Count; x++)
{
HttpPostedFile hpf = context.Request.Files[x] as HttpPostedFile;
string FileName = string.Empty;
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE")
{
string[] files = hpf.FileName.Split(new char[] { '\\' });
FileName = files[files.Length - 1];
}
else
{
FileName = hpf.FileName;
}
if (hpf.ContentLength == 0)
continue;
string savedFileName = context.Server.MapPath("~/Uploads/" + FileName);
try
{
hpf.SaveAs(savedFileName);
}
catch (Exception ex)
{
}
r.Add(new ViewDataUploadFilesResult()
{
thumbnailUrl = savedFileName,
name = FileName,
length = hpf.ContentLength,
type = hpf.ContentType,
url = string.Format("/Uploads/{0}", FileName),
deleteUrl = string.Format("/Uploads/{0}", FileName)
});
var uploadedFiles = new
{
files = r.ToArray()
};
//was returning a new json string everytime, so then duplicating if
//sending multiple files. Example, file 1 was in first position,
//then file 1 & 2 in second position, and so on. So, I only grab,
//the last JSON instance to get all files.
if (x == (context.Request.Files.Count - 1))
{
var jsonObj = JsonConvert.SerializeObject(uploadedFiles, Formatting.Indented);
string jsonHttpOutputStream = jsonObj.ToString();
context.Response.Write(jsonHttpOutputStream);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
public class ViewDataUploadFilesResult
{
public string thumbnailUrl { get; set; }
public string name { get; set; }
public int length { get; set; }
public string type { get; set; }
public string url { get; set; }
public string deleteUrl { get; set; }
}
而在一个基本的水平,这将呈现和工作。然后,你必须在这里和那里调整一些代码,以使其运行得如何。尽管如此,这个处理程序正是您正确处理上传所需的全部内容。祝你好运!
任何人都可以提供这个样本 – Sivajith 2014-01-23 07:44:23
我试过这个,不适合我。如果我分别运行这个东西,并有一个处理程序运行从VS我得到的错误:SyntaxError:意外的令牌<,如果我在vs中运行整个事情(包括所有的HTML文件等)我得到的错误:方法不允许 – WtFudgE 2015-06-25 09:44:52
这里是一个很好的MVC5示例:https://github.com/CodeHeight/jQuery-File-Upload.MVC5 – JoshYates1980 2017-01-29 03:02:39
- 1. Blueimp jQuery文件上传与数据库集成
- 2. 使用blueimp上传文件上传东西blueimp文件上传
- 3. Blueimp文件上传插件,进度条完成文件上传
- 4. Jquery Blueimp文件上传回调
- 5. BlueImp jQuery文件上传和ModSecurity错误
- 6. jquery文件上传php数据库blueimp
- 7. jQuery BlueImp文件上传授权
- 8. blueimp jQuery文件上传未被触发
- 9. jquery文件上传(blueimp) - 文件上传按ID编号
- 10. 分块文件上传与blueimp和oneuploaderbundle
- 11. 文件上传与jQuery的blueimp文件上传,不能在IE9工作
- 12. 如何在ASP.NET中实现Blueimp jQuery文件上传
- 13. Blueimp多文件上传
- 14. 使用Jquery BlueImp上传器上传大文件后延迟
- 15. 一次在blueimp中上传一个文件jquery上传
- 16. Blueimp jquery文件上传 - 上传文件在不同的文件夹
- 17. Blueimp jQuery文件上传和symfony2:问题与自定义上传处理程序
- 18. 在完成jQuery文件上传时触发asp.net事件
- 19. jquery文件上传(blueimp) - IE9不支持多文件选择?
- 20. BlueImp文件上传插件不工作
- 21. blueimp jquery文件上传空文件上传结果struts2,fileitems为空
- 22. Blueimp文件上传器 - Chrome文件夹上传限制
- 23. jquery文件上传blueimp无法更改错误消息文本
- 24. Blueimp jQuery File上传插件与Codeigniter一步一步?
- 25. BlueImp文件上传额外参数
- 26. Blueimp上传 - 丢弃原始文件
- 27. 如何在blueimp/jQuery上设置一个动态url上传文件上传
- 28. 使用Blueimp jQuery的文件上传与WordPress和联系表7的文件上传
- 29. 如何使用blueimp文件上传生成的图片预览?
- 30. blueimp jquery文件上传 - “完成”,“完整”回调不适用于IE 9
我不能让进度条工作。 – hakan 2015-02-25 18:08:40