Missing content-type boundary. at Microsoft.AspNetCore.Http.Features.FormFeature.GetBoundary(MediaTypeHeaderValue contentType, Int32 lengthLimit) at Microsoft.AspNetCore.Http.Features.FormFeature.d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.ModelBinding.FormValueProviderFactory.d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.ModelBinding.CompositeValueProvider.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.ModelBinding.CompositeValueProvider.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<g__Bind|0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__23.MoveNext()
最近的.net core 项目中经常报如上的错误信息,该如何解决?
代码中有没有用到Missing content-type boundary
?
没有
@Impossible: 建议提供一下对应的 Action 代码
@dudu:
[HttpPost] public IActionResult Index(string path = "upload") { var file = Request.Form.Files[0]; if (file != null) { string dirName = path; string dir = Path.Combine(_env.WebRootPath ?? _env.ContentRootPath, dirName); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string ext = Path.GetExtension(file.FileName); string guid = Guid.NewGuid().ToString("N"); string fileName = guid + ext; string filePath = Path.Combine(dir, fileName); using (FileStream fs = System.IO.File.Create(filePath)) { file.CopyTo(fs); fs.Flush(); } string picUrl = "/" + Path.Combine(dirName, fileName).Replace("\\", "//"); return Ok(picUrl); } return Ok(""); }
整个项目只有这一个上传图片的地方,其他地方没有涉及到上传文件。
@Impossible: 上传文件的前端代码是怎么写的?
@dudu: 是用Uploadify.js框架
@Impossible: 问题与上传请求的 content-type
有关
首先看你这报错应该是上传文件的地方报的错,没有进一步代码不好分析