B4J Question [server] How to handle postmultipart

Chris Guanzon

Active Member
Licensed User
Longtime User
Hello, everyone!

Please help me. How can I handle a postmultipart in JServer?

I have a client using httpjob postmultipart.
Client:
Libraries.httpJob.PostMultipart(Variables.URL & path, CreateMap("key1": "values1", "key2": "values2"), Null)

I tried using getMultipartData and this is what I got.
Return:
(MyMap)
{key1=Part{n=key1,fn=null,ct=null,s=7,tmp=true,file=null},
key2=Part{n=key2,fn=null,ct=null,s=7,tmp=true,file=null}}

This is the code I used on my server.
server:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    resp.ContentType = "application/json"

    Dim reqMap, respMap As Map
    reqMap.Initialize
    respMap.Initialize

    reqMap = req.GetMultipartData(File.Combine(File.DirApp, "www"), 100000000)

   Log(reqMap)
end sub
 

Chris Guanzon

Active Member
Licensed User
Longtime User
Thank you very much, Sir Erel! ☺️

Solution:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    resp.ContentType = "multipart/form-data"

    Dim reqMap As Map = req.GetMultipartData(File.Combine(File.DirApp, "www"), 1000000)
    For Each Key As String In reqMap.Keys
        Dim p As Part = reqMap.Get(Key)
        Dim Value As String = p.GetValue("utf8")
        Log(Key & ": " & Value)
    Next

end sub
 
Upvote 0
Top