1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-05-15 17:35:24 +03:00

fix binary file http upload

This commit is contained in:
ficeto 2015-05-09 14:21:53 +03:00
parent 8ce762db16
commit 7001086920

View File

@ -441,8 +441,6 @@ readfile:
argByte = client.read(); argByte = client.read();
if(argByte == 0x0A){ if(argByte == 0x0A){
line = client.readStringUntil(0x0D);
client.readStringUntil(0x0A);
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.print("Write File: "); DEBUG_OUTPUT.print("Write File: ");
DEBUG_OUTPUT.println(_currentUpload.buflen); DEBUG_OUTPUT.println(_currentUpload.buflen);
@ -450,7 +448,28 @@ readfile:
if(_fileUploadHandler) _fileUploadHandler(); if(_fileUploadHandler) _fileUploadHandler();
_currentUpload.size += _currentUpload.buflen; _currentUpload.size += _currentUpload.buflen;
_currentUpload.buflen = 0; _currentUpload.buflen = 0;
if(line.startsWith("--"+boundary)){
argByte = client.read();
if((char)argByte != '-'){
//continue reading the file
_currentUpload.buf[_currentUpload.buflen++] = 0x0D;
_currentUpload.buf[_currentUpload.buflen++] = 0x0A;
goto readfile;
} else {
argByte = client.read();
if((char)argByte != '-'){
//continue reading the file
_currentUpload.buf[_currentUpload.buflen++] = 0x0D;
_currentUpload.buf[_currentUpload.buflen++] = 0x0A;
_currentUpload.buf[_currentUpload.buflen++] = (uint8_t)('-');
goto readfile;
}
}
uint8_t endBuf[boundary.length()];
client.readBytes(endBuf, boundary.length());
if(strstr((const char*)endBuf, (const char*)(boundary.c_str())) != NULL){
_currentUpload.status = UPLOAD_FILE_END; _currentUpload.status = UPLOAD_FILE_END;
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.print("End File: "); DEBUG_OUTPUT.print("End File: ");
@ -461,7 +480,9 @@ readfile:
DEBUG_OUTPUT.println(_currentUpload.size); DEBUG_OUTPUT.println(_currentUpload.size);
#endif #endif
if(_fileUploadHandler) _fileUploadHandler(); if(_fileUploadHandler) _fileUploadHandler();
if(line == ("--"+boundary+"--")){ line = client.readStringUntil(0x0D);
client.readStringUntil(0x0A);
if(line == "--"){
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.println("Done Parsing POST"); DEBUG_OUTPUT.println("Done Parsing POST");
#endif #endif
@ -471,10 +492,9 @@ readfile:
} else { } else {
_currentUpload.buf[_currentUpload.buflen++] = 0x0D; _currentUpload.buf[_currentUpload.buflen++] = 0x0D;
_currentUpload.buf[_currentUpload.buflen++] = 0x0A; _currentUpload.buf[_currentUpload.buflen++] = 0x0A;
const char * lineChars = line.c_str();
uint32_t i = 0; uint32_t i = 0;
while(i < os_strlen(lineChars)){ while(i < boundary.length()){
_currentUpload.buf[_currentUpload.buflen++] = lineChars[i++]; _currentUpload.buf[_currentUpload.buflen++] = endBuf[i++];
if(_currentUpload.buflen == 1460){ if(_currentUpload.buflen == 1460){
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.println("Write File: 1460"); DEBUG_OUTPUT.println("Write File: 1460");