
Hi everyone,
I have a APi , that returns a file.
I wrote a piece of code to write the file and save it. But I get this Error on line 8
"- $exception {"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters."} System.FormatException"
var client111 = new RestClient("http://..../file/a2e7af2f6621f156572a717e81f2f6df");
client111.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("gateway-token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzeXN0ZW0iOiJqdWRpY2lhcnlCYWNrT2ZmaWNlIiwiY3JlYXRlVGltZSI6IjE0MDEwMjE5MDg1MTEyMDQ3IiwidXNlcklkIjoiZDQyZmZkODYtMDQxMy00NWY4LTk3ZWEtMGYwYjRjNzBhNWI2IiwidW5pcXVlRmllbGRzIjpbeyJ1c2VybmFtZSI6ImFkbWluIn1dLCJkYXRhIjoiYWRtaW4ifQ.jkOIE104yo42FC6Lqv700f2sL4MmQfRgyvsTyQRwn4o");
request.AddHeader("Cookie", "token=fa378724f8301652788469325");
IRestResponse response = client111.Execute(request);
//Console.WriteLine(response.Content);
byte[] byteArrayPart = Convert.FromBase64String(response.Content);
const string fileNamePart = "C:\\Image\\image88.png";
byte[] dataArray = byteArrayPart;
using (FileStream fileStream = new FileStream(fileNamePart, FileMode.Create))
{
// Write the data to the file, byte by byte.
for (int i = 0; i < dataArray.Length; i )
{
fileStream.WriteByte(dataArray[i]);
}
}
The response model is like this: