I'm trying to upload a file in a web server and the server is trying to send the file to the endpoint on the ESP but it seems like the ajax with the url with that esp endpoint is failling, I'm trying to send the file uploaded in the form with jquery: jquery.min.js version 3.2.1
I've got [E][WebServer.cpp:633] _handleRequest(): request handler not found in the monitor serie
the code of the endpoint in the webserver is:
{% extends 'base.html'%} {% block title %} Actualizar {% endblock %} {% block content %}
<div class="container mt-5 mb-5 px-10 ">
<div class="row">
<div class="col-md-6 offset-md-3 text-center">
<h2>Actualizar Firmware</h2><br>
<form action="/update" method="POST" enctype="multipart/form-data" id='upload_form' role="form">
<div class="form-group">
<input type="file" name="binfile" class="form-control" required><br>
<button type="submit" class="btn btn-secondary">Actualizar</button>
</div><br>
<div id='prg'>Progress: 0%</div>
</form>
{% if message %}
<p class="alert alert-danger">{{ message }}</p>
{% endif %}
</div>
</div>
</div>
<script>
$('form').submit(function(e){
e.preventDefault();
var form = $('#upload_form')[0];
var data = new FormData(form);
$.ajax({
url: '/update',
type: 'POST',
data: data,
contentType: false,
processData:false,
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener('progress', function(evt) {
if (evt.lengthComputable) {
var per = evt.loaded / evt.total;
$('#prg').html('progress: ' + Math.round(per*100) + '%');
}
}, false);
return xhr;
},
success:function(d, s) {
console.log('success!')
},
error: function (a, b, c) {
}
})
})
</script>
{% endblock %}
the relevant code in the esp
#include <Arduino.h>
#include <WiFi.h>
#include <WebServer.h>
#include <Update.h>
#include <ArduinoOTA.h>
#include "QueryLib.h"
WebServer server(80);
server.on("/update", HTTP_POST, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", (Update.hasError()) ? "FAIL" : "OK");
ESP.restart();
}, []() {
HTTPUpload & upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.printf("Update: %s\n", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) {
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) {
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Update.printError(Serial);
}
}
});