How to receive and process a long string sent over serial? I want to receive about 5kb of data in Base64 format. The following code does not work. Only a few characters are received, sometimes CPU crashes.

String content = "";
char character;

while (Serial.available()) {
       character = Serial.read();
       content.concat(character);
}


I do not care about ram usage since on ESP32 there is plenty.
How can I get all the data? Example input: https://pastebin.com/wYG5AhHK
I had to read until delimiter :D 

String receive() {
        String content = "";
        content = Serial.readStringUntil('\r');
        return content;
    }


Now it is fine. I will also change String to large char array.