Search code examples
javaandroidfileuploadnanohttpd

file uploading error nanohttpd


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?


Solution

  • 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.