问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/16149415/file-uploading-error-nanohttpd