Send the last photo fragment when the size is a multiple of 2048
The fragment loop only wrote a full fragment while more data followed it, and only wrote a partial one when there was a remainder. When the photo length was an exact multiple of PHOTO_FRAGMENT_SIZE the final fragment was never sent, the length check failed and the upload was reported as incomplete. Replace it with a loop that sends what is left, up to one fragment at a time. Checked on the host for every length from 0 to 299999 and on a XIAO ESP32-S3 Sense (uploads return 200 OK). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>pull/149/head
parent
8c7109e67f
commit
fc4b6de49a
|
|
@ -130,15 +130,12 @@ bool PrusaConnect::SendDataToBackend(String *i_data, int i_data_length, String i
|
|||
size_t fbLen = (PhotoToSend != NULL) ? PhotoToSend->len : 0;
|
||||
|
||||
/* sending photo */
|
||||
for (size_t i = 0; i < fbLen; i += PHOTO_FRAGMENT_SIZE) {
|
||||
if ((i + PHOTO_FRAGMENT_SIZE) < fbLen) {
|
||||
sendet_data += client.write(fbBuf, PHOTO_FRAGMENT_SIZE);
|
||||
fbBuf += PHOTO_FRAGMENT_SIZE;
|
||||
|
||||
} else if ((fbLen % PHOTO_FRAGMENT_SIZE) > 0) {
|
||||
size_t remainder = fbLen % PHOTO_FRAGMENT_SIZE;
|
||||
sendet_data += client.write(fbBuf, remainder);
|
||||
}
|
||||
size_t remaining = fbLen;
|
||||
while (remaining > 0) {
|
||||
size_t chunk = (remaining < PHOTO_FRAGMENT_SIZE) ? remaining : PHOTO_FRAGMENT_SIZE;
|
||||
sendet_data += client.write(fbBuf, chunk);
|
||||
fbBuf += chunk;
|
||||
remaining -= chunk;
|
||||
}
|
||||
client.println("\r\n");
|
||||
SystemLog.AddEvent(LogLevel_Verbose, F("Photo sent"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue