【摘要】 netcore 图片上传考必过小编为大家整理了关于netcore 图片上传的信息,希望可以帮助到大家!
netcore 图片上传
标签: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); }
前端传值 多了括号,导致后台接收不到图片
netcore 图片上传
标签:pos exception tco img header task env form file
以上就是netcore 图片上传的内容,更多资讯请及时关注考必过网站,最新消息小编会第一时间发布,大家考试加油!