file uploading error nanohttpd

纵饮孤独 提交于 2019-12-21 06:18:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!