2

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?

Stephan
  • 41,764
  • 65
  • 238
  • 329
gajiwala
  • 43
  • 4

2 Answers2

4

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.

Stephan
  • 41,764
  • 65
  • 238
  • 329
Paul Hawke
  • 1,141
  • 10
  • 12
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.

Harsh Vakharia
  • 2,104
  • 1
  • 23
  • 26
  • Can I know in which location the files gets upload, I tried the same as given but unable to find. Thanks in advance. – Arun Feb 22 '14 at 15:23