The input is not a valid Base-64 string as it contains a non-base64 character

后端 未结 11 1754
难免孤独
难免孤独 2020-11-27 14:37

I have a REST service that reads a file and sends it to another console application after converting it to Byte array and then to Base64 string. This part works, but when th

11条回答
  •  没有蜡笔的小新
    2020-11-27 15:15

    Probably the string would be like this data:image/jpeg;base64,/9j/4QN8RXh... First split for / and get the second token.

    var StrAfterSlash = Face.Split('/')[1];
    

    Then Split for ; and get the first token which will be the format. In my case it's jpeg.

    var ImageFormat =StrAfterSlash.Split(';')[0];
    

    Then remove the line data:image/jpeg;base64, for the collected format

    CleanFaceData=Face.Replace($"data:image/{ImageFormat };base64,",string.Empty);
    

提交回复
热议问题