Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1.  
  2.         public ActionResult Tupload(){
  3.  
  4.             return View();
  5.         }
  6.  
  7.        
  8.  
  9.         [HttpPost]
  10.         [ValidateAntiForgeryToken]
  11.         //public JsonResult DoUpload([FromForm] Object obj, [FromForm] IFormFile file) { <-- Model bound complex types must not be abstract or value types and must have a parameterless constructor.
  12.         //public async Task<IActionResult> Post(List<IFormFile> files) <- files is always empty
  13.         //public JsonResult DoUpload(IFormFile files) { <- Model bound complex types must not be abstract or value types and must have a parameterless constructor.
  14.         //public JsonResult DoUpload(UploadedDocument files) { <- attachment attribute, which is IFormFile is null
  15.         //public JsonResult DoUpload ( [FromBody] UploadedDocument files) { <- 415 Unsupported Media Type
  16.         //public JsonResult DoUpload ( [FromForm] UploadedDocument files) { <- {"attachment":null}
  17.         //public JsonResult DoUpload (UploadedDocument file, IFormFile doc) { <- Model bound complex types must not be abstract or value types and must have a parameterless constructor.
  18.         //public JsonResult DoUpload (List<IFormFile> files ) { <- files is null
  19.         //public JsonResult DoUpload (Object files) { <- returns {} when (attempting to return Json(files))
  20.         public JsonResult DoUpload (List<IFormFile> files) {
  21.            
  22.             return Json(files.Count);
  23.            
  24.             //return Json(new { filename = files.Name, size = files.Length } );
  25.            
  26.             /*
  27.             long size = files.Sum(f => f.Length);
  28.  
  29.             // full path to file in temp location
  30.             var filePath = Path.GetTempF    ileName();
  31.  
  32.             foreach (var formFile in files)
  33.             {
  34.                 if (formFile.Length > 0)
  35.                 {
  36.                     using (var stream = new FileStream(filePath, FileMode.Create))
  37.                     {
  38.                         await formFile.CopyToAsync(stream);
  39.                     }
  40.                 }
  41.             }
  42.  
  43.             // process uploaded files
  44.             // Don't rely on or trust the FileName property without validation.
  45.  
  46.             return Json(new { count = files.Count, size, filePath});
  47.             */
  48.             //return Json(Request.Form);
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement