Making a PUT request using HTTPClient is very slow
Posted: Fri Nov 26, 2021 8:50 am
I'm trying to upload a 40 MB csv file to a cloud server, using HTTP PUT request. But it's taking 15-20 mins. I've tried making the PUT request using cURL and same file from terminal and it happens under 3 minis. How can I improve the speed/solve the issue.
Example Code:
Example Code:
Code: Select all
void send_file() {
if ((wifiMulti.run() == WL_CONNECTED)) {
File file = SD.open("/file0.csv");
if (!file) {
Serial.println("Failed to open file");
return;
}
const auto filesize = file.size();
HTTPClient http;
http.addHeader("Content-Type", "text/csv");
http.addHeader("Content-Length", String(filesize, DEC));
http.setAuthorization(username, password);
char finalurl[256];
sprintf(finalurl, "%s/%s", apiUrl, file.name());
// Serial.println(finalurl);
http.addHeader("Content-Type", "text/csv");
http.addHeader("Content-Length", String(filesize, DEC));
http.setAuthorization(username, password);
http.begin(finalurl);
int http_code;
const auto A = millis();
http_code = http.sendRequest("PUT", &file, filesize);
Serial.printf("\n time-keep: %lus", (millis() - A) / 1000);
http.end();
file.close();
}
}