You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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());
});
}
}
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>" ?
I follow your point - it does appear that the implementation of getParts chose to return Map<String, HttpPart>. This does fulfill the Collection interface, but you're correct that this doesn't support duplicate field names / keys. I also noticed that RFC2388 says that field names should be unique, but I believe in practice forms often have multiple values mapped to one name (e.g. radio buttons).
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 :
My simple request :
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 :
The text was updated successfully, but these errors were encountered: