esp8266 / esp8266/Arduino

ESP8266WebServer HTTPUpload does not support non-file fields

Open
#7,533 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

### Basic Infos

- [x] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [x] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [x] I have tested that the issue is present in current master branch (aka latest git).
- [x] I have searched the issue tracker for a similar issue.
- [x] If there is a stack dump, I have decoded it.
- [x] I have filled out all fields below.

#### Platform

- Hardware: WeMos D1 R1 dev kit
- Core Version: 2.7.4
- Development Env: Arduino IDE
- Operating System: Ubuntu

### Settings in IDE

- Module: WeMos D1 R1
- Flash Mode: (not listed in Tools menu?)
- Flash Size: 4MB
- lwip Variant: v2 Lower Memory
- Reset Method: (not listed in Tools menu?)
- Flash Frequency: (not listed in Tools menu?)
- CPU Frequency: 80Mhz
- Upload Using: Serial
- Upload Speed: 921600

### Problem Description

I'm working with [ESP8266WebServer](https://github.com/esp8266/Arduino/blob/668b33ddf15e20051c6dc5b4a33525accf608706/libraries/ESP8266WebServer/src/ESP8266WebServer.h) and a `multipart/form-data` HTML form submitted to that server. The library correctly exposes an `HTTPUpload` object for an uploaded file, and I can retrieve that file data on the esp8266 without a problem. However, if the form also contains _other_ data items, then these are seemingly not exposed; `server.args()` is 0, and the `HTTPUpload` struct has no space for additionally-passed form arguments. I don't know whether there's another way to retrieve this data and it's not documented, or if there's another way to retrieve this data and it _is_ documented and I missed it, or if there isn't a way.

### [MCVE](https://stackoverflow.com/help/mcve) Sketch

HTML file to create the upload:

```html


```

and a sketch (elided for simplicity)

```cpp
#include
ESP8266WebServer server(80);

void setup() {
// skip some not-relevant parts about connecting to local wifi so that the esp8266 has an IP
server.on("/upload", HTTP_POST, [](){ server.send(200); }, handleFileUpload );
server.begin();
}

void loop() {
server.handleClient();
}

void handleFileUpload(){ // upload a new file to the SPIFFS
HTTPUpload& upload = server.upload();
if(upload.status == UPLOAD_FILE_START){
String filename = upload.filename;
Serial.print("This is the field name for the upload, which should be 'my_file_for_upload' since that's what the form called it: ");
Serial.println(upload.name);
//////////////////////////////////////////////////////////////////////////////
// Here's the problem: where do I get the value of extra_field from?
//////////////////////////////////////////////////////////////////////////////
} else {
// skip the rest of the file handling because it's not relevant to the question
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.