Web API (backend) - InsertPicture failing : Unable to translate bytes [FF] at index 0 from specified code page to Unicode.

9 meses atrás
I keep getting this error when trying to use the API InsertPicture call,:
Unable to translate bytes [FF] at index 0 from specified code page to Unicode.

I pull the binary image data directly from a http request and then make it the body of the insert (PUT) request and can not get past this error.

here is the example vb.net code:

Public Shared Function GetDobaImageDataBinary(ByVal imgUrl As String) As Byte()
            Dim request As HttpWebRequest = WebRequest.Create(imgUrl)
            Dim response As HttpWebResponse = request.GetResponse()
            Dim imageStream As Stream = response.GetResponseStream()
            Dim memoryStream = New MemoryStream()
            imageStream.CopyTo(memoryStream)
            Return memoryStream.ToArray
        End Function


Dim imageByteArray As Byte() = GetDobaImageDataBinary(imgUrl)

'create request object
                Dim apiCallURL = "(my store url)/api-backend/Picture/InsertPicture?" & "mimeType=" & HttpContext.Current.Server.UrlEncode(mimeType) & "&seoFilename=productimage&isNew=true&validateBinary=true"
                Dim httpWebRequest As HttpWebRequest
                httpWebRequest = WebRequest.Create(apiCallURL)
                httpWebRequest.ContentType = "application/json-patch+json"
                httpWebRequest.Method = "PUT"
                httpWebRequest.Accept = "application/json"
                httpWebRequest.Headers("Authorization") = authorizationToken

                'set the content of the request
                Dim imageStream As Stream = httpWebRequest.GetRequestStream()
                imageStream.Write(imageByteArray, 0, imageByteArray.Length)
                imageStream.Close()

Any help would be appreciated, thanks!
9 meses atrás
Hi. Please specify which version of the plugin you are using, and on which side the error occurs, that is, do you receive this error in response to a request or even at the stage of sending a request?
9 meses atrás
Sergei-k wrote:
Hi. Please specify which version of the plugin you are using, and on which side the error occurs, that is, do you receive this error in response to a request or even at the stage of sending a request?


Thanks for the reply, here is the info:
- version 4.60.03 of API
- the error is in the repones to the request that i setup in my above post, i already have other successful calls to the API, like inserting a product, et. However, InsertPicture seems to not like the body data even though it is set to the binary data of the image as the API notes.

Here is the response code, it hits the catch with a 500 error response:

'Get response
                Dim pictureID As Integer
                Try
                    response = httpWebRequest.GetResponse()
                    Dim responseStream = response.GetResponseStream()
                    Dim reader As New StreamReader(responseStream)
                    Dim responseFromServer = reader.ReadToEnd()
                    Dim pictureJson As JObject
                    pictureJson = JObject.Parse(responseFromServer)
                    pictureID = pictureJson.SelectToken("id")
                    Return pictureID
                Catch ex As WebException
                    Return 0
                End Try

So the response error is:
"The remote server returned an error: (500) Internal Server Error."

And when I look at the store logs I see:
Unable to translate bytes [FF] at index 0 from specified code page to Unicode.
9 meses atrás
Hi. Unfortunately, I have not yet found a way to use this version of the method either. I suggest you replace it with the following implementation and rebuild your client for it


[ProducesResponseType(typeof(PictureDto), StatusCodes.Status200OK)]
public virtual async Task<IActionResult> InsertPicture(IFormFile fileBinary,
  [FromQuery, Required] string mimeType,
  [FromQuery, Required] string seoFilename,
  [FromQuery] string altAttribute = null,
  [FromQuery] string titleAttribute = null,
  [FromQuery] bool isNew = true,
  [FromQuery] bool validateBinary = true)
{
  var pictureBinary = new byte[fileBinary.Length];
  using var reader = fileBinary.OpenReadStream();
  await reader.ReadAsync(pictureBinary, 0, pictureBinary.Length);
  reader.Close();

  var picture = await _pictureService.InsertPictureAsync(pictureBinary, mimeType, seoFilename,
    altAttribute, titleAttribute, isNew, validateBinary);

  return Ok(picture.ToDto<PictureDto>());
}
9 meses atrás
Thanks for the reply Sergey,

Sergei-k wrote:
Hi. Unfortunately, I have not yet found a way to use this version of the method either. I suggest you replace it with the following implementation and rebuild your client for it


So are you saying that the current API picture load call does not work?

Also, on the code you provided, are you saying to update that in the API plugin or is that updated in the base store code?
9 meses atrás
Yes, the current implementation does not work, more precisely, it is not entirely clear in what format it expects data, and it needs to be replaced with the one I gave above, replaced exactly in the code of the plugin itself
9 meses atrás
Sergei-k wrote:
Yes, the current implementation does not work, more precisely, it is not entirely clear in what format it expects data, and it needs to be replaced with the one I gave above, replaced exactly in the code of the plugin itself


Thanks for the update, I will message you shortly.
9 meses atrás
Hi. Today we released a minor version that made changes to the InsertPicture method and fixed a number of other inaccuracies.
9 meses atrás
Sergei-k wrote:
Hi. Today we released a minor version that made changes to the InsertPicture method and fixed a number of other inaccuracies.


Excellent, thanks!
9 meses atrás
Sergei-k wrote:
Hi. Today we released a minor version that made changes to the InsertPicture method and fixed a number of other inaccuracies.


How do we get the updated web API package if we got it in the mobile app bundle? I do not see an updated mobile app bundle to download.