Description
I am creating a gcloud http function which must receive a "form-data" form with a "medias" field which can contain up to 3 files, here is the basic code:
Gcloud Java function :
package functions;
import com.google.cloud.functions.HttpFunction;
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;
import java.io.BufferedWriter;
import java.io.IOException;
public class HelloWorld implements HttpFunction {
@Override
public void service(HttpRequest request, HttpResponse response)
throws IOException {
var parts = request.getParts();
parts.forEach(
(e1, e2) -> {
System.out.println(e1);
System.out.println(e2.getFileName().get());
});
}
}
My simple request :
curl --location --request POST 'http://localhost:8080/' \
--form 'medias=@"/file1.jpeg"' \
--form 'medias=@"/file2.jpeg"'
Oddly, "request.getParts();" returns a "Map<String, HttpPart>" and therefore I don't see how to retrieve multiple files of the same submitted parameter. In debugging, I get a nice "java.lang.IllegalStateException: Duplicate key medias (attempted merging values com.google.cloud.functions.invoker.http.HttpRequestImpl$HttpPartImpl@49e848cf and com.google.cloud.functions.invoker.http .HttpRequestImpl$HttpPartImpl@6d5d7015)"
I can see that "getQueryParameters()" return correctly "Map<String, List>" and not "Map<String, String>" because a parameter name can have many value but why "getParts()" return "Map<String, HttpPart>" and not "Map<String, List>" ?
maven :
<dependency>
<groupId>com.google.cloud.functions</groupId>
<artifactId>functions-framework-api</artifactId>
<version>1.0.4</version>
<scope>provided</scope>
</dependency>