我查看了很多线程,但找不到问题的答案......
所以我可以在我的设备上启动网络服务器,当我尝试上传文件时,浏览器显示“上传成功”,但我不能'在我的设备上找不到文件,我不知道它是否已上传到设备。我已经设置了所有权限并在我的方法中区分post
和。get
serve
我想我必须从参数文件中保存上传的Map<String, String>
文件。
我怎么能那样做?这是正确的方法吗?
这是我的代码片段:
private class MyHTTPD extends NanoHTTPD {
public MyHTTPD() throws IOException {
super(PORT);
}
public Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> parms, Map<String, String> files) {
if (method.equals(Method.GET)) {
return get(uri, method, headers, parms, files);
}
return post(uri, method, headers, parms, files);
}
public Response get(String uri, Method method, Map<String, String> headers, Map<String, String> parms, Map<String, String> files) {
String get = "<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>";
return new Response(get);
}
public Response post(String uri, Method method, Map<String, String> headers, Map<String, String> parms, Map<String, String> files) {
String post = "<html><body>Upload successfull</body></html>";
return new Response(post);
}
}