回答
您可以使用確切的演示文件,而無需使用先前評論中鏈接的.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. 在CodeIgniter中集成Blueimp(Jquery上傳器)
- 3. BlueImp/jQuery文件上傳
- 4. blueimp jquery文件上傳WordPress
- 5. 自定義文件上傳按鈕與blueimp jquery文件上傳
- 6. 多文件上傳 - Blueimp jQuery上傳
- 7. 使用blueimp上傳文件上傳東西blueimp文件上傳
- 8. 在blueimp文件上傳的jQuery插件
- 9. 在ckeditor中集成blueimp文件上載
- 10. Blueimp文件上傳插件,進度條完成文件上傳
- 11. 檢查文件上傳是blueimp jQuery的文件上傳插件全成
- 12. Jquery Blueimp文件上傳回調
- 13. BlueImp jQuery文件上傳和ModSecurity錯誤
- 14. blueimp jQuery的文件上傳不工作
- 15. 使用blueimp jQuery文件上傳
- 16. blueimp jQuery文件上傳未被觸發
- 17. jQuery BlueImp文件上傳授權
- 18. blueimp jQuery文件在div上傳
- 19. blueimp jQuery的文件上傳processalways不叫
- 20. jquery文件上傳php數據庫blueimp
- 21. blueimp jQuery文件上傳PHP MySQL數據庫集成第三個文本框
- 22. jquery文件上傳(blueimp) - 文件上傳按ID編號
- 23. blueimp/jQuery-File-Upload與Laravel如何集成?
- 24. BlueImp jQuery上傳使用ASP.NET MVC
- 25. 分塊文件上傳與blueimp和oneuploaderbundle
- 26. 文件上傳與jQuery的blueimp文件上傳,不能在IE9工作
- 27. 如何在ASP.NET中實現Blueimp jQuery文件上傳
- 28. 將jQuery文件上傳插件集成到Rails中
- 29. Blueimp多文件上傳
- 30. blueimp多個文件上傳
我不能讓進度條工作。 – hakan 2015-02-25 18:08:40