user37224: 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

user37229: 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.

37224: <p>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.</p>

<pre><code>String content = "";
char character;

while (Serial.available()) {
       character = Serial.read();
       content.concat(character);
}
</code></pre>

<p>I do not care about ram usage since on ESP32 there is plenty.
How can I get all the data? Example input: <a href="https://pastebin.com/wYG5AhHK" rel="nofollow noreferrer">https://pastebin.com/wYG5AhHK</a></p>
 37229: <p>I had to read until delimiter :D </p>

<pre><code>String receive() {
        String content = "";
        content = Serial.readStringUntil('\r');
        return content;
    }
</code></pre>

<p>Now it is fine. I will also change String to large char array.</p>
