I am using ASP.NET Core to create API request to upload avatar for each company using this action
[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);
}
}
I am sending upload request using postman like this http://i.imgur.com/JvqKAiU.png
it returns
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
I was facing the same issue yesterday using Postman to send a file to an ASPNET Core Api.
In my case, I forgot to remove the Content-type header, so, postman was trying to send it as JSON (or something like that).
When I removed the header property everything worked as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With