标签:pos exception tco img header task env form file
public async Task<JsonResult> AjaxUploud(IFormCollection formCollection) { // return Json("成功"); if (HttpContext.Request.Form.Files.Count == 0) { throw new BizException("文件数为0"); } var files = Request.Form.Files; //var fileUrl = await StoreUserPostedImageAsync(postFile, 0); List<string> filePathResultList = new List<string>(); foreach (var file in files) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.ToString().Trim(‘"‘); string filePath = hostingEnv.WebRootPath + $@"\uploud\Pictures\"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string suffix = fileName.ToString().Split(‘.‘)[1]; if (!pictureFormatArray.Contains(suffix)) { } fileName = Guid.NewGuid() + "." + suffix; string fileFullName = filePath + fileName; using (FileStream fs = System.IO.File.Create(fileFullName)) { file.CopyTo(fs); fs.Flush(); } filePathResultList.Add($"/uploud/Pictures/{fileName}"); } var result = new { filePathResultList, filePathResultList.Count }; return Json(result); }
前端传值 多了括号,导致后台接收不到图片
标签:pos exception tco img header task env form file
原文地址:https://www.cnblogs.com/njccqx/p/13500741.html