B4J Question jServer - GetMultipartData file multiple not working


Licensed User
Longtime User
Hi, I'm looking for solution for issue I found - if I use file input element with option "multiple" to be able to upload for examle 10 files in one time, then result of
Dim parts As Map = req.GetMultipartData(File.DirApp & "/upload_tmp", 10000000)
is always map with just last file from multipart array. All files are correctly uploaded to server, but you are not able to get their names and copy them to final destination and remove temp ones, because you know only last one. Enctype is set correctly to multipart/form/data. Webpage code is correct, it is now just ported to B4J server usage.

I think it is jServer/GetMultipartData implementation bug - probably the reason is that all files have the same html "field" name like "filesforupload[]" and map is then overwritten each time...?


B4X founder
Staff member
Licensed User
Longtime User
It is indeed not supported by req.GetMultipartData.

Untested code:
Public GetMultiparts(Folder As String, MaxSize As Long) As List
  Dim config As JavaObject
  config.InitializeNewInstance("javax.servlet.MultipartConfigElement", Array(Folder, MaxSize, MaxSize, 81920))
  Dim fAs JavaObject
  f.InitializeNewInstance("java.io.File", Array(Folder))
  Dim parser As JavaObject
  parser.InitializeNewInstance("org.eclipse.jetty.util.MultiPartInputStreamParser", Array(req.InputStream, req.ContentType, config, f))
  Dim parts As JavaObject = parser.RunMethod("getParts", Null)
  Dim result() As Object = parts.RunMethod("toArray", Null)
  Return result
End Sub
Upvote 0