WebApi - Upload Avatar

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 year ago
[/i]Seems like there might be a bug with the function `ApiFrontendCustomerUploadAvatarPostWithHttpInfo`

line 5942:

if (body != null && body.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(body); // http body (model) parameter
            }
            else
            {
                localVarPostBody = body;  // byte array
            }



When checking the type of body if the request is of type byte[] it was getting passed as byte[] but the api request does not accept that as a valid request error that keeps popping up is

[i]>"System.Text.DecoderFallbackException: Unable to translate bytes [FF] at index 0 from specified code page to Unicode.\r\n   at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)\r\n   at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] ....



If I changed the condition on line 5942 to

if (body != null && body.GetType() == typeof(byte[]))


The request comes back valid and results is shown on the storefront as expected.

What are your thoughts? is it a bug ? or am I doing something wrong?
1 year ago
What WebApi do you use?
1 year ago
The team uses this
https://www.nopcommerce.com/en/web-api

we grabbed the c# compiler code from swagger
1 year ago
I'm sorry, but the code you provided is not part of our plugin, and we can't tell if it's correct or not without seeing the entire method. You should contact the authors of the ApiFrontendCustomerUploadAvatarPostWithHttpInfo method for more details.

[email protected] wrote:
The team uses this
https://www.nopcommerce.com/en/web-api

we grabbed the c# compiler code from swagger
1 year ago
I am a little confused

if you navigate to https://app.swaggerhub.com/apis/nopCommerceAPI/nop-commerce_web_api_frontend/v1.06#/Customer/post_api_frontend_Customer_UploadAvatar


Go to Export > Csharp then navigate the downloaded zip to src\IO.Swagger\Api\CustokmerApi.cs right on line 5833
you should see the function (see image https://ibb.co/vLW5qDT)

I thought the nopcommerce team developed this plugin (see author on plugin page https://ibb.co/s3kxKwQ)
1 year ago
That's right, the plugin was developed by our team, but, unfortunately, we are not responsible for client code generation. In your case, the client is generated by https://swagger.io/ algorithms .

For clarity, here is part of the code for the Upload Avatar method from our plugin:


public virtual async Task<IActionResult> UploadAvatar(IFormFile fileBinary,
  [FromQuery, Required] string fileName,
  [FromQuery, Required] string contentType)
{
  .....
  
  if (fileBinary != null && !string.IsNullOrEmpty(fileName))
  {
    ....

    var customerPictureBinary = new byte[fileBinary.Length];
    using var reader = fileBinary.OpenReadStream();
    await reader.ReadAsync(customerPictureBinary, 0, customerPictureBinary.Length);
    reader.Close();
    if (customerAvatar != null)
      customerAvatar = await _pictureService.UpdatePictureAsync(customerAvatar.Id, customerPictureBinary,
        contentType, null);
    else
      customerAvatar = await _pictureService.InsertPictureAsync(customerPictureBinary, contentType, null);
  }

  .....

  return Ok(new CustomerAvatarModelDto {AvatarUrl = avatarUrl});
}


[email protected] wrote:
I am a little confused

if you navigate to https://app.swaggerhub.com/apis/nopCommerceAPI/nop-commerce_web_api_frontend/v1.06#/Customer/post_api_frontend_Customer_UploadAvatar


Go to Export > Csharp then navigate the downloaded zip to src\IO.Swagger\Api\CustokmerApi.cs right on line 5833
you should see the function (see image https://ibb.co/vLW5qDT)

I thought the nopcommerce team developed this plugin (see author on plugin page https://ibb.co/s3kxKwQ)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.