Asp.net web api 使用IFormFile时缺少右括号
我正在使用ASP.NET Core创建API请求,以便使用此操作为每个公司上载头像Asp.net web api 使用IFormFile时缺少右括号,asp.net-web-api,Asp.net Web Api,我正在使用ASP.NET Core创建API请求,以便使用此操作为每个公司上载头像 [HttpPost("{company_id}/updateLogo")] [RequestFormSizeLimitAttribute(valueCountLimit: 147483648)] public async Task<IActionResult> updateCompanyLogo(IFormFile imgfile,int company_id) {
[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);
}
}
[HttpPost({company_id}/updateLogo”)]
[RequestFormSizeLimitAttribute(valueCountLimit:147483648)]
公共异步任务更新公司徽标(IFormFile imgfile,int company_id)
{
字符串图像名称;
//上传文件
if(imgfile==null | | imgfile.Length==0)
imageName=“default logo.jpg”;
其他的
{
imageName=Guid.NewGuid()+imgfile.FileName;
var path=_hostingEnvironment.WebRootPath+$@“\Imgs\{imageName}”;
if(imgfile.ContentType.ToLower().包含(“图像”))
{
使用(var fileStream=newfilestream(路径,FileMode.Create))
{
等待imgfile.CopyToAsync(fileStream);
}
}
}
使用(var db=new AppDb())
{
等待db.Connection.OpenAsync();
var查询=新公司模型(db);
var result=await query.FindOneAsync(公司id);
如果(结果==null)
返回NotFound();
result.logo=图像名称;
等待结果。UpdateAsync();
返回Ok(结果);
}
}
我发送上传请求使用邮递员像这样
它回来了
ArgumentException:密钥'M�C�hC�}�冀
m6t(4����C�^�X������X���� ��)<代码>j��ŗ�NP��-�60�G֘���E�̡��代码>�Z�6.������4.�9��аa���![ܢ��不
是无效的JQuery语法,因为缺少右括号。
参数名称:key querytomvc
昨天我也遇到了同样的问题,使用Postman将文件发送到ASPNET核心Api 在我的例子中,我忘记删除Content-type头,所以postman试图将其作为JSON(或类似的东西)发送
当我删除header属性时,一切正常。是的,这也是我的问题。很抱歉,我忘了在此处添加我的答案。.感谢分享您的解决方案谢谢,两个小时的挫折,您刚刚救了我一天。