首页 新闻 会员 周边 捐助

.net core 出现 Missing content-type boundary.的异常信息。

0
[已解决问题] 解决于 2020-04-27 15:30
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 项目中经常报如上的错误信息,该如何解决?

Impossible的主页 Impossible | 初学一级 | 园豆:72
提问于:2018-09-19 15:14
< >
分享
最佳答案
0

代码中有没有用到Missing content-type boundary

奖励园豆:5
dudu | 高人七级 |园豆:30778 | 2018-09-19 17:48

没有

Impossible | 园豆:72 (初学一级) | 2018-09-19 17:49

@Impossible: 建议提供一下对应的 Action 代码

dudu | 园豆:30778 (高人七级) | 2018-09-19 17:51

@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 | 园豆:72 (初学一级) | 2018-09-19 17:53

@Impossible: 上传文件的前端代码是怎么写的?

dudu | 园豆:30778 (高人七级) | 2018-09-19 17:55

@dudu: 是用Uploadify.js框架

Impossible | 园豆:72 (初学一级) | 2018-09-19 17:56

@Impossible: 问题与上传请求的 content-type 有关

dudu | 园豆:30778 (高人七级) | 2018-09-19 18:02
其他回答(1)
0

首先看你这报错应该是上传文件的地方报的错,没有进一步代码不好分析

MrNice | 园豆:3468 (老鸟四级) | 2018-09-19 16:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册