0
我正尝试使用NanoHttpd库通过使用来自表单的POST请求将文件上传到我的Android服务器。我确实收到服务器端的POST请求。我的问题是如何从POST请求中检索文件,以便将其保存在设备内存的某个位置。使用NanoHttpd从POST请求中检索文件
形式:
<form action='?' method='post' enctype='multipart/form-data'>
<input type='file' name='file' />`enter code here`
<input type='submit'name='submit' value='Upload'/>
</form>
发球方法:
@Override
public Response serve (IHTTPSession session) {
Method method = session.getMethod();
String uri = session.getUri();
if (Method.POST.equals(method)) {
//get file from POST and save it in the device memory
}
...
}
通过适应这个代码到我的解决方案,我能够将文件保存在内存中,只是因为我想。此外,我能够通过使用相同的密钥从session.getParams()hashmap中检索原始文件名。 – zxzak