我正在使用ASP.NET Core创建API请求,以使用此操作为每个公司上传头像 [HttpPost("{company_id}/updateLogo")] [RequestFormSizeLimitAttribute(valueCountLimit: 147483648)] public async TaskIActionResult updateCompanyLogo(IFor
[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); } }
我正在使用这样的邮递员发送上传请求
http://i.imgur.com/JvqKAiU.png
它返回
我昨天使用Postman将文件发送到ASPNET Core Api时遇到了同样的问题.ArgumentException: The key ‘M�C�hC�}�jI
m6t(4����c�^�X������X���� ��)j��ŗ�np��-�60�G֘���e�̡��
�z�6������4�9��аa���![ܢ��T’
is invalid JQuery syntax because it is missing a closing bracket.
Parameter name: key NormalizeJQueryToMvc
在我的情况下,我忘了删除Content-type标头,因此,邮递员试图将其作为JSON(或类似的东西)发送.
当我删除标题属性时,一切都按预期工作.