I am using NanoHTTPD webserver 2.1.0 on the Java Desktop Env. (without Android)
Everything works fine ... but not uploading the file using the POST method (PUT is not supported by forms)
Here is my HTML code:
<form method="post" enctype="multipart/form-data"> choose a file<br> <input name="file" type="file" size="50" maxlength="100000""> <button type="submit">upload</button> </form>
And here is my server-side method:
public Response serve(IHTTPSession session) { if (session.getMethod() == Method.POST) { Map<String, String> files = new HashMap<String, String>(); session.parseBody(files);
And here is the problem: temp file does not exist. In the end, there is another temporary file with a different βnumberβ, and this seems to be the correct file because the contents are the same as the contents of the downloaded file. So how to get the correct name temp-filename?
Another problem: the temp file contains the contents of the POST hole:
-----------------------------115801144322347 Content-Disposition: form-data; name="file"; filename="filename.txt" Content-Type: application/octet-stream -->content of the uploaded file -----------------------------115801144322347--
This is a problem if the content is pic or binary.
NanoHTTPD does not seem to make any special requests with POST. it is always the same ... saving the request to a tmp file and serving the page. So: - How to get the correct temp file? -> I think this is a mistake. I get the correct path and name, but the "number" is broken. idk ... should I temporarily change the java tmp path if downloading occurs and then always delete the file. Then I have only one tmp file, regardless of any naming convention? - how to kill html request header from file
Or am I doing something wrong? Is this the right way to upload files to nanohttpd?
thank you for your help!
source share