asp.net-web-api – 当我使用IFormFile时缺少一个结束括号
发布时间:2020-12-16 09:13:25 所属栏目:asp.Net 来源:网络整理
导读:我正在使用ASP.NET Core创建API请求,以使用此操作为每个公司上传头像 [HttpPost("{company_id}/updateLogo")] [RequestFormSizeLimitAttribute(valueCountLimit: 147483648)] public async TaskIActionResult updateCompanyLogo(IFormFile imgfile,int compa
我正在使用ASP.NET Core创建API请求,以使用此操作为每个公司上传头像
[HttpPost("{company_id}/updateLogo")] [RequestFormSizeLimitAttribute(valueCountLimit: 147483648)] public async Task<IActionResult> updateCompanyLogo(IFormFile imgfile,int company_id) { string imageName; // upload file if (imgfile == null || imgfile.Length == 0) imageName = "default-logo.jpg"; else { imageName = Guid.NewGuid() + imgfile.FileName; var path = _hostingEnvironment.WebRootPath + $@"Imgs{imageName}"; if (imgfile.ContentType.ToLower().Contains("image")) { using (var fileStream = new FileStream(path,FileMode.Create)) { await imgfile.CopyToAsync(fileStream); } } } using (var db = new AppDb()) { await db.Connection.OpenAsync(); var query = new CompanyModel(db); var result = await query.FindOneAsync(company_id); if (result == null) return NotFound(); result.logo = imageName; await result.UpdateAsync(); return Ok(result); } } 我正在使用这样的邮递员发送上传请求 它返回
解决方法
我昨天使用Postman将文件发送到ASPNET Core Api时遇到了同样的问题.
在我的情况下,我忘了删除Content-type标头,因此,邮递员试图将其作为JSON(或类似的东西)发送. 当我删除标题属性时,一切都按预期工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- .net – RESTful WCF的裸最低配置
- asp.net-mvc – Layout.cshtml上的ASP.NET MVC搜索框
- asp.net-mvc – 使用Linq返回空字符串到SQL – 没有行的相关
- ASP.NET:如何在没有任何子域的情况下获取域名?
- asp.net – .NET Framework 4.0是否需要重启?
- asp.net – MvcTextTemplateHost未找到
- 使用ASP.Net Core MVC和ASP.Net Web Api在Angular2 App中进
- ASP.Net HttpHandler ProcessRequest()触发两次
- asp.net-mvc-4 – 在asp.net mvc应用程序中集成Power BI报告
- 圆角按钮ASP.NET
推荐文章
站长推荐
- asp.net – 确定当前页面是否需要授权?
- asp.net – 为什么我的jQuery UI datepicker在初
- asp.net-mvc – 通过webapp文件和apache站点配置
- 如何从ASP.NET MVC中的窗体身份验证拦截401?
- asp.net-core – 为什么默认的mvc6模板针对多个D
- asp.net – 实体框架CTP5,代码优先.可选的导航属
- asp.net – web.config转换和location元素
- .NET Core多平台开发体验[1]: Windows
- asp.net – 如何以编程方式从LDAP检索信息
- asp.net-mvc – ASP.NET MVC 2中的空查询字符串参
热点阅读