mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
FIX: Reset the 'upload_error' variable after web file upload error (#20340)
* FIX: Reset the 'upload_error' variable after signaling the error to enable the next upload action. * ADD: Introduce HandleUploadUFSDone() to display information messages for uploaded files in UFS and handle errors. ADD: Include '?fsz=' web-argument (filesize) in the upload button click function.
This commit is contained in:
parent
b69cc802db
commit
a13e83e1e6
@ -2777,7 +2777,10 @@ void HandleUploadLoop(void) {
|
|||||||
if (UPLOAD_FILE_START == upload.status) {
|
if (UPLOAD_FILE_START == upload.status) {
|
||||||
Web.upload_error = 0;
|
Web.upload_error = 0;
|
||||||
upload_error_signalled = false;
|
upload_error_signalled = false;
|
||||||
upload_size = 0;
|
char tmp[16];
|
||||||
|
|
||||||
|
WebGetArg("fsz", tmp, sizeof(tmp)); // filesize
|
||||||
|
upload_size = (!strlen(tmp)) ? 0 : atoi(tmp);
|
||||||
|
|
||||||
UploadServices(0);
|
UploadServices(0);
|
||||||
|
|
||||||
@ -2785,18 +2788,25 @@ void HandleUploadLoop(void) {
|
|||||||
Web.upload_error = 1; // No file selected
|
Web.upload_error = 1; // No file selected
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SettingsSave(1); // Free flash for upload
|
|
||||||
|
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_UPLOAD D_FILE " %s"), upload.filename.c_str());
|
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_UPLOAD D_FILE " %s (%d bytes)"), upload.filename.c_str(), upload_size);
|
||||||
|
|
||||||
#ifdef USE_UFILESYS
|
#ifdef USE_UFILESYS
|
||||||
if (UPL_UFSFILE == Web.upload_file_type) {
|
if (UPL_UFSFILE == Web.upload_file_type) {
|
||||||
|
const uint32_t freeBytes = (UfsFree() * 1024);
|
||||||
|
if (upload_size > freeBytes) {
|
||||||
|
Web.upload_error = 9; // File too large
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!UfsUploadFileOpen(upload.filename.c_str())) {
|
if (!UfsUploadFileOpen(upload.filename.c_str())) {
|
||||||
Web.upload_error = 2;
|
Web.upload_error = 2; // Not enough space
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // USE_UFILESYS
|
#endif // USE_UFILESYS
|
||||||
|
|
||||||
|
SettingsSave(1); // Free flash for upload
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***** Step2: Write upload file
|
// ***** Step2: Write upload file
|
||||||
@ -2890,7 +2900,7 @@ void HandleUploadLoop(void) {
|
|||||||
Web.config_block_count++;
|
Web.config_block_count++;
|
||||||
}
|
}
|
||||||
#ifdef USE_UFILESYS
|
#ifdef USE_UFILESYS
|
||||||
else if (UPL_UFSFILE == Web.upload_file_type) {
|
else if (!Web.upload_error && UPL_UFSFILE == Web.upload_file_type) {
|
||||||
if (!UfsUploadFileWrite(upload.buf, upload.currentSize)) {
|
if (!UfsUploadFileWrite(upload.buf, upload.currentSize)) {
|
||||||
Web.upload_error = 9; // File too large
|
Web.upload_error = 9; // File too large
|
||||||
return;
|
return;
|
||||||
@ -2925,7 +2935,7 @@ void HandleUploadLoop(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef USE_UFILESYS
|
#ifdef USE_UFILESYS
|
||||||
else if (UPL_UFSFILE == Web.upload_file_type) {
|
else if (!Web.upload_error && UPL_UFSFILE == Web.upload_file_type) {
|
||||||
UfsUploadFileClose();
|
UfsUploadFileClose();
|
||||||
}
|
}
|
||||||
#endif // USE_UFILESYS
|
#endif // USE_UFILESYS
|
||||||
|
@ -803,9 +803,11 @@ const char UFS_FORM_FILE_UPGc2[] PROGMEM =
|
|||||||
"</div>";
|
"</div>";
|
||||||
|
|
||||||
const char UFS_FORM_FILE_UPG[] PROGMEM =
|
const char UFS_FORM_FILE_UPG[] PROGMEM =
|
||||||
"<form method='post' action='ufsu' enctype='multipart/form-data'>"
|
"<form method='post' action='ufsu?fsz=' enctype='multipart/form-data'>"
|
||||||
"<br><input type='file' name='ufsu'><br>"
|
"<br><input type='file' name='ufsu'><br>"
|
||||||
"<br><button type='submit' onclick='eb(\"f1\").style.display=\"none\";eb(\"f2\").style.display=\"block\";this.form.submit();'>" D_UPLOAD "</button></form>"
|
"<br><button type='submit' "
|
||||||
|
"onclick='eb(\"f1\").style.display=\"none\";eb(\"but6\").style.display=\"none\";eb(\"f2\").style.display=\"block\";this.form.action+=this.form[\"ufsu\"].files[0].size;this.form.submit();'"
|
||||||
|
">" D_UPLOAD "</button></form>"
|
||||||
"<br><hr>";
|
"<br><hr>";
|
||||||
const char UFS_FORM_SDC_DIRa[] PROGMEM =
|
const char UFS_FORM_SDC_DIRa[] PROGMEM =
|
||||||
"<div style='text-align:left;overflow:auto;height:250px;'>";
|
"<div style='text-align:left;overflow:auto;height:250px;'>";
|
||||||
@ -858,6 +860,40 @@ const char HTTP_EDITOR_FORM_END[] PROGMEM =
|
|||||||
|
|
||||||
#endif // #ifdef GUI_EDIT_FILE
|
#endif // #ifdef GUI_EDIT_FILE
|
||||||
|
|
||||||
|
void HandleUploadUFSDone(void) {
|
||||||
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
||||||
|
|
||||||
|
HTTPUpload& upload = Webserver->upload();
|
||||||
|
|
||||||
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_UPLOAD_DONE));
|
||||||
|
|
||||||
|
WifiConfigCounter();
|
||||||
|
UploadServices(1);
|
||||||
|
|
||||||
|
WSContentStart_P(PSTR(D_INFORMATION));
|
||||||
|
|
||||||
|
WSContentSendStyle();
|
||||||
|
WSContentSend_P(PSTR("<div style='text-align:center;'><b>" D_UPLOAD " <font color='#"));
|
||||||
|
if (Web.upload_error) {
|
||||||
|
WSContentSend_P(PSTR("%06x'>" D_FAILED "</font></b><br><br>"), WebColor(COL_TEXT_WARNING));
|
||||||
|
char error[100];
|
||||||
|
if (Web.upload_error < 10) {
|
||||||
|
GetTextIndexed(error, sizeof(error), Web.upload_error -1, kUploadErrors);
|
||||||
|
} else {
|
||||||
|
snprintf_P(error, sizeof(error), PSTR(D_UPLOAD_ERROR_CODE " %d"), Web.upload_error);
|
||||||
|
}
|
||||||
|
WSContentSend_P(error);
|
||||||
|
Web.upload_error = 0;
|
||||||
|
} else {
|
||||||
|
WSContentSend_P(PSTR("%06x'>" D_SUCCESSFUL "</font></b><br>"), WebColor(COL_TEXT_SUCCESS));
|
||||||
|
}
|
||||||
|
WSContentSend_P(PSTR("</div><br>"));
|
||||||
|
|
||||||
|
XdrvCall(FUNC_WEB_ADD_MANAGEMENT_BUTTON);
|
||||||
|
|
||||||
|
WSContentStop();
|
||||||
|
}
|
||||||
|
|
||||||
void UfsDirectory(void) {
|
void UfsDirectory(void) {
|
||||||
if (!HttpCheckPriviledgedAccess()) { return; }
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
||||||
|
|
||||||
@ -1457,7 +1493,8 @@ bool Xdrv50(uint32_t function) {
|
|||||||
// Webserver->on(F("/ufsu"), HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop);
|
// Webserver->on(F("/ufsu"), HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop);
|
||||||
Webserver->on("/ufsd", UfsDirectory);
|
Webserver->on("/ufsd", UfsDirectory);
|
||||||
Webserver->on("/ufsu", HTTP_GET, UfsDirectory);
|
Webserver->on("/ufsu", HTTP_GET, UfsDirectory);
|
||||||
Webserver->on("/ufsu", HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop);
|
//Webserver->on("/ufsu", HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop);
|
||||||
|
Webserver->on("/ufsu", HTTP_POST, HandleUploadUFSDone, HandleUploadLoop);
|
||||||
#ifdef GUI_EDIT_FILE
|
#ifdef GUI_EDIT_FILE
|
||||||
Webserver->on("/ufse", HTTP_GET, UfsEditor);
|
Webserver->on("/ufse", HTTP_GET, UfsEditor);
|
||||||
Webserver->on("/ufse", HTTP_POST, UfsEditorUpload);
|
Webserver->on("/ufse", HTTP_POST, UfsEditorUpload);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user