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