Limitation for multipart/form-data form
imadamahmid1 opened this issue · 1 comments
Feature Request
The current httpClient of bdk doesn't support multiple values for a given form key.
With the current httpClient of bdk, this works:
httpClient.formParam("file", new File("path/to/myFile/");
But when we keep adding other files like the snippet bellow doesn't work because we keep overriding the map containing the parameters:
httpClient.formParam("file", new File("path/to/myFirstFile/");
httpClient.formParam("file", new File("path/to/mySecondFile/");
Description of Problem:
I checked the code and it seems like the form params are stored in a map, and the value of "file" will be overridden each time which will prevent us from having a field with many files. The implementation ideally would support adding of multiple files under the same key and use boundary to separate the files under the field file.
Ideally we want to to be able to add several files in one field of form data in an iterative way, like this:
httpClient.formParam("file", new File("path/to/myFirstFile/");
httpClient.formParam("file", new File("path/to/mySecondFile/");
httpClient.formParam("file", new File("path/to/myThirdFile/");
Potential Solutions:
N/A
We could think of several solutions:
- user passes a
List<File>
as form param and we update theApiClientWebClient
andApiClientJersey2
implementations to handle a list of files (list of strings are already handled for urlencoded forms):
It has the advantage of not breaking the API - or we update the
HttpClient.RequestConfig
class so that it contains aMultiValuedMap
as formParams and we pass a Map<String, List> as formParams in theinvokeApi
method:
We will still need to do the above (handing aList<File>
as formParam value)
However this will break the current contract/API (note thatMultiValuedMap<K,V>
extendsMap<K, List<V>>
)