Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing a closing bracket when I use IFormFile

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

like image 445
Dot Freelancer Avatar asked Feb 04 '23 16:02

Dot Freelancer


1 Answers

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.

like image 142
Bruno Gimenes Avatar answered May 24 '23 18:05

Bruno Gimenes