Esp32 error 400 upload spiffs wav file to web server using http post

Thanks for posting all the code, and output as code. Before getting to your stated issue.... it's excessive to start a separate task to connect to WiFi. It could just as easily be called from setup, since it just runs briefly and then the task ends with an infinite loop.

The wavHeader code is long and tediously lists 44 byte offsets. Computers are really good at counting. There's also no need to mask with 0xFF if you're assigning to byte -- any "extra" bits get lopped off anyway. You do need a cast to avoid a narrowing warning, but something like the following is more readable and less error-prone:

constexpr int headerSize = 44;

#define U32_BYTES_LE(x) static_cast<byte>(x), \
  static_cast<byte>(x >> 8), static_cast<byte>(x >> 16), static_cast<byte>(x >> 24)

void wavHeader(byte *dest, int wavSize) {
  unsigned chunkSize = wavSize + headerSize - 8;
  byte header[] = {
    'R', 'I', 'F', 'F',
    U32_BYTES_LE(chunkSize),
    'W', 'A', 'V', 'E',
    'f', 'm', 't', ' ',
    U32_BYTES_LE(0x10),
    0x01, 0x00, 0x01, 0x00, 0x80, 0x3E, 0x00, 0x00,
    0x00, 0x7D, 0x01, 0x00, 0x02, 0x00, 0x10, 0x00,
    'd', 'a', 't', 'a',
    U32_BYTES_LE(wavSize),
  };
  static_assert(sizeof(header) == headerSize);
  memcpy(dest, header, sizeof(header));
}

The static_assert catches mistakes like forgetting the space at the end of the "fmt " tag

This topic's title mentions web sockets, but I don't see any of those. You might as well print the response body when the response is not 200 -- the error message can be helpful. If you have a random boundary assigned to a variable, you should use that variable when possible; the order of these two statements can be flipped to be:

  String boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW";
  client.addHeader("Content-Type", "multipart/form-data; boundary=" + boundary);

Does your ESP32 board have PSRAM? Is it Enabled (near the bottom of the board-specific options in the bottom half of the Tools menu)? If not, the maximum String size is 64KB. If you exceed the max, the alloc/concat has no effect and the object is marked invalid. Your .wav is 100KB bigger.

You could try a .wav that is under the limit, which would have to be short and perhaps low-res, to see if all the other code works.

It would be more efficient overall to implement a Stream that can do the HTTP multipart stuff; that wraps the File, which is also a subclass of Stream. HTTPClient::sendRequest has an overload that takes a Stream.

Has the server code been tested with something like curl, which can do the upload?

curl -v -F file=@recording.wav 'http://192.168.1.112:5000/upload'