Error loading nanohttpd file

I used the code below to download files using NanoHTTPD, but nothing loads and gives no temporary path.

Code:

new Response( HTTP_OK, MIME_HTML, "<html><body><form name='up' enctype='multipart/form-data'><input type='file' name='file' /><br /><input type='submit'name='submit' value='Upload'/></form></body></html>" ); 

I successfully load the page, and after clicking the download button, my url also changes to

 http://IP_ADD:PORT/file?file=closed.png&submit=Upload 

But nothing downloads to my phone.

Could you help me?

+2
source share
2 answers

Here is the solution

 new Response(HTTP_OK, MIME_HTML, "<html><body><form name='up' method='post' enctype='multipart/form-data'><input type='file' name='file' /><br /><input type='submit'name='submit' value='Upload'/></form></body></html>"); 

You just need to add method='post' to the form.

+1
source

Keep in mind that if you are using NanoHttpd, the download should be saved as a temporary file when processing the request.

The server uses the standard java.io.tmpdir to decide where the temporary files go. But on most phones, the system points to this variable on the SD card.

Therefore, you might want to add permissions to access an external SD card to your Android manifest.

+4
source

Source: https://habr.com/ru/post/1486183/


All Articles