// Web WebAPI or acquired form data stream (bulk file upload)
public UploadFile a JsonResult ()
{
// HttpPostedFileBase FileBase Request.Files = [ "fileToUploadKeyID"];
HttpPostedFileBase FileBase Request.Files = [0]; // Get client upload the collection of files
string fileName = string.Empty; // relative file path
String = errMsg An string.Empty;
IF (FileBase == null || fileBase.ContentLength == 0)
{
errMsg An = "file is empty";
}
the else
{
the MaxSize = 1024 1024 * int *. 4;
IF (fileBase.InputStream.Length> the MaxSize)
{
errMsg An = "file is too large";
}
else
{
try
{
fileName = System.IO.Path.GetFileName(fileBase.FileName);
fileName = "/upload/" + DateTime.Now.ToString("yyMMddHHmmssff") + "." + fileName.Split('.')[1];
var filePath = System.Web.HttpContext.Current.Server.MapPath(fileName);
fileBase.SaveAs(filePath);//保存文件
}
catch
{
errMsg = "上传失败";
}
}
}
return Json(new { errMsg = errMsg, fileName = fileName });
}
Asp.Net or WebAPI get form data stream (bulk file uploads)
Guess you like
Origin www.cnblogs.com/lgq880821/p/11590634.html
Recommended
Ranking