我通过 MVC、jQuery、Ajax 创建了文件上传器。但它仅适用于 1 到 3 KB 的文件,不适用于较大的文件。如何上传较大的文件?
HTML:
<input type="file" name="bfile" size="50" id="bfile"/>
<input type="butt
AppAttachmentsController-控制器代码:
public string file_upload(string file_name, string file_binary)
{
byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(file_binary);
MemoryStream stream = new MemoryStream(byteArray);
string path=Server.MapPath(Url.Content("~/upload/file"))+"\\"+file_name;
using (var fileStream = new FileStream(path, FileMode.Create))
stream.CopyTo(fileStream);
return "1";
}
jQuery,阿贾克斯:
function AttachemtPost() {
var file_name = $("#bfile").val();
var data = "file_name=" + file_name;
var file = document.getElementById('bfile').files[0];
var file_binary = file.getAsBinary();
var file_size = file.fileSize;
var file_text = file.getAsText("");
alert('file :' + file_binary);
alert('file size:' + file_size);
data = "file_name=" + file_name + "&file_binary=" + file_binary;
ajaxlocalcall2(null, "POST", '@Url.Content("~/AppAttachments/file_upload")', data, "", "", "html", "oncontactinfosave");
}