Fileupload over Wifi super slow

I'm reading a file and uploading it to a webserver on the local network over Wifi. BUt it's is extremely slow. About 6 seconds (!) for a 11KB file. This makes uploading photos almost impossible. That can't be right?

Anyone have any tips on how to speed things up?

  File file = SD.open("/outbox/001/me2.jpg", FILE_READ);
  if (!file) {
    Serial.println("booboo");
    return;
  }
  String size = String(file.size());

  Serial.println("filesize " + size);

  Serial.print("connecting to ");
  Serial.println(host);

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 4000;


  if (!client.connect(host, httpPort)) {
      Serial.println("connection failed");
      return;
  }

  // We now create a URI for the request
  String url = "/upload";

  Serial.print("Requesting URL: ");
  Serial.println(url);

  // This will send the request to the server
  client.print(String("POST ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n");
 client.print("Content-Length: ");
 client.println(size);
 client.println("");
 Serial.println("start sending");
 while (file.available()){
   client.write(file.read());
 }
 Serial.println("end sending");
 file.close();
 client.println("");
 Serial.println();
 Serial.println("closing connection");
 client.stop();
 delay(2000);
 SD.end();

Please note I'm using an ESP32 dev board. This has a built in SD socket.

OK just tested a 4.4MB file. Uploading it lasted for over 10 minutes... no idea on it;s progress but I cancelled it eventually.

I then removed the actual sending over WiFi.

Basically replaced:

client.write(file.read());

with

file.read();

That completed in about 90seconds, so it's safe to say the client.write() takes very long and is what should be optimized, but how...?

don't send the file by one byte TCP packets.

byte buff[1024];
while (file.available()){
int length = file.readBytes(buff, sizeof(buff));
client.write(buff, length);
}

or use BufferedPrint from StreamLib