HttpPostedFileBase to byte [] how to save the encoding?

So the scenario is this: The user uploads the file, my code turns this file into an array of bytes, and the array is passed to the external API. And it works great.

The problem is that this file contains special characters, such as Γ¦, ΓΈ, Γ₯, and when byte [] is converted to characters again, these characters are replaced with "?".

public void UploadFile(HttpPostedFileBase file){ var binary = new byte[file.ContentLength]; file.InputStream.Read(binary, 0, file.ContentLength; var result = API.UploadDocument(binary); //Passes the file to the external API } 

Is it possible to add some encoding information to a byte array or InputStream, or is it API dependent to make sure the text is correctly encoded when converting byte [] back to characters?

+4
source share
1 answer

The responsibility of the API is to correctly convert the byte array to characters. If you have access to the API code, you must add the encoding parameters to the UploadDocument method

+2
source

Source: https://habr.com/ru/post/1383878/


All Articles