I have an android app that uses NanoHTTPD to serve HTML context. I'm using NanoHTTP 2.0.5 in my App.
There's a problem with file uploads. Suppose I upload a file named kr d.mp4; it gets uploaded but renamed to k (starting from one character before space till last char in filename including extension is removed).
Any file upload that has space shows this behaviour. I tried other file name :
ORIGINAL GOT THIS
-----------------------------
NO_SPACE.TXT NO_SPACE.TXT (works as expected)
ABC DEF.txt AB
AB1234 gf.txt AB123
A D.txt Failed to upload ???
How do I fix this issue ?
I got this working with help from IRC channel #android-dev by user : memoryleak. It was an encoding related issue.
To fix it do this when uploading on :
Client side (Javascript) :
formdata.append("filedata", file, encodeURIComponent(file['name']));
Server Side (NanoHTTPD) :
URLDecoder.decode(session.getParms().get(entry.getKey()), "UTF-8");