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();
}
}