Question

I used below code to upload files using NanoHTTPD, but nothing is being uploaded nor giving me temp path.

Code is:

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 am successfully getting upload page, and after clicking on upload button, my URL is also changing to

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

But nothing is uploading to my phone.

can you help me?

Was it helpful?

Solution 2

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 need to just add method='post' in form.

OTHER TIPS

Bear in mind, if you are using NanoHttpd, that the upload will need to be stored as a temp file while processing the request.

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

You might want, therefore, to add permissions for accessing the external SD card to your Android Manifest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top