- public JsonResult File()
- {
- try
- {
- DirectoryInfo dir = System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"\File");
- Stream files = Request.Files[0].InputStream;
- string path = dir.FullName + @"" + Request.Files[0].FileName;
- using (FileStream fs = new FileStream(path,FileMode.Append,FileAccess.Write,FileShare.ReadWrite))
- {
- byte[] buffer = new byte[512];
- long contentLength = files.Length;
- int length = files.Read(buffer, 0, buffer.Length);
- while (length > 0)
- {
- fs.Write(buffer, 0, length);
- buffer = new byte[512];
- length = files.Read(buffer, 0, buffer.Length);
- }
- fs.Flush();
- fs.Close();
- }
- return Json(new { success = true, message = path });
- }
- catch (Exception ex)
- {
- return Json(new { success = false, message = "error" });
- }
-
-
-
- }
复制代码
这个是自己以前写的接收大文件上传的接口,自己测试上传1g文件,没有问题。
|