Sub Handle(req As ServletRequest, resp As ServletResponse)
If req.Method <> "POST" Then
resp.SendError(500, "method not supported.")
Return
End If
'we need to call req.InputStream before calling GetParameter.
'Otherwise the stream will be read internally (as the parameter might be in the post body).
Dim In As InputStream = req.InputStream
Dim reqType As String = req.GetParameter("type")
Select reqType
Case "text"
Dim tr As TextReader
tr.Initialize(In)
resp.Write("Message received successfully.")
Case "file"
Dim su As StringUtils
Dim filename As String =su.DecodeUrl(req.GetParameter("filename"),"UTF8")
If filename = "" Then
resp.SendError(500, "Missing filename parameter")
Return
End If
Dim out As OutputStream = File.OpenOutput(Main.filesFolder, filename, False)
File.Copy2(In, out)
out.Close
resp.Write("OK, file uploaded successfully : " & filename & ", size=" & File.Size(Main.filesFolder, filename))
End Select
End Sub