Access parameters supplied with a file upload POST request?
Posted: Mon May 20, 2019 11:47 am
Hi all,
I'm not really sure where the line between "newbie" and "advanced" is, so I'm just going to post this here - feel free to move it if inappropriate.
I'm setting up an ESP8266 web server, and I have a page wherein I can upload files to the server's SPIFFS file system. I would like to expand upon this, and also specify a text field whereby the user can specify the path of the destination file when it is saved (currently is it saved in the root of the file system, and uses the original file name of the source file).
I have some HTML with a simple form, that includes the file upload as before, as well as an accompanying text field wherein the user can specify the path. This is the relevant part of the HTML:
For GET requests, I would be able to access the parameter "file_path" in my request handler by invoking the following:
But for POST requests, this doesn't seem to work - the above print statement prints an empty string, i.e. only a newline character.
For now, my code just tries to print the value in the text as above but saves the file as before (i.e. in root, with the original file name). I tried compiling my code with the HTTP_SERVER debug flag enabled, and I upload a simple test file with the string "/test/test.txt" in the file_path field. I see the following at the end of theserial debug output for the request:
So my parameters are being received and parsed, but are not available using
Does anyone have any ideas?
if relevant, my response handler function is here:
https://pastebin.com/LxkjNJUm
And the full output of the debugger for the request (not including the output for serving up the "success.html" response) is here:
https://pastebin.com/k3P5NhCZ
Matt
I'm not really sure where the line between "newbie" and "advanced" is, so I'm just going to post this here - feel free to move it if inappropriate.
I'm setting up an ESP8266 web server, and I have a page wherein I can upload files to the server's SPIFFS file system. I would like to expand upon this, and also specify a text field whereby the user can specify the path of the destination file when it is saved (currently is it saved in the root of the file system, and uses the original file name of the source file).
I have some HTML with a simple form, that includes the file upload as before, as well as an accompanying text field wherein the user can specify the path. This is the relevant part of the HTML:
Code: Select all
<form method="post" enctype="multipart/form-data" action='/upload'>
<input type="file" name="name">
<input type="text" placeholder="Destination file path" aria-label="path" name="file_path">
<input type="submit" value="Upload">
</form>
For GET requests, I would be able to access the parameter "file_path" in my request handler by invoking the following:
Code: Select all
Serial.println(server.arg("file_path"));
But for POST requests, this doesn't seem to work - the above print statement prints an empty string, i.e. only a newline character.
For now, my code just tries to print the value in the text as above but saves the file as before (i.e. in root, with the original file name). I tried compiling my code with the HTTP_SERVER debug flag enabled, and I upload a simple test file with the string "/test/test.txt" in the file_path field. I see the following at the end of theserial debug output for the request:
PostArg Name: file_path
PostArg Type: text/plain
PostArg Value: /test/text.txt
So my parameters are being received and parsed, but are not available using
Code: Select all
.server.arg("file_path");
Does anyone have any ideas?
if relevant, my response handler function is here:
https://pastebin.com/LxkjNJUm
And the full output of the debugger for the request (not including the output for serving up the "success.html" response) is here:
https://pastebin.com/k3P5NhCZ
Matt