Skip to content

Commit bad5af9

Browse files
authored
Add support for large uploads to HTTPClient (espressif#8006)
1 parent 82de342 commit bad5af9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: libraries/HTTPClient/src/HTTPClient.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,21 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size)
619619

620620
// send Payload if needed
621621
if(payload && size > 0) {
622-
if(_client->write(&payload[0], size) != size) {
622+
size_t sent_bytes = 0;
623+
while(sent_bytes < size){
624+
size_t sent = _client->write(&payload[sent_bytes], size - sent_bytes);
625+
if (sent == 0){
626+
log_w("Failed to send chunk! Lets wait a bit");
627+
delay(100);
628+
sent = _client->write(&payload[sent_bytes], size - sent_bytes);
629+
if (sent == 0){
630+
log_e("Failed to send chunk!");
631+
break;
632+
}
633+
}
634+
sent_bytes += sent;
635+
}
636+
if(sent_bytes != size){
623637
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
624638
}
625639
}

0 commit comments

Comments
 (0)