Vertx Web 客户端为 Multipart/form-data 抛出 HTTP 415 不支持的媒体类型

Vertx Web Client throwing HTTP 415 Unsupported Media Type for Multipart/form-data

该服务接收来自移动客户端的多部分请求,并将请求传递给下游服务以上传图片。我在我的下游服务中看到 415 Unsupported Media Type

 private void makeRequest(HttpRequest<Buffer> httpRequest,
                             Promise<Object> future,
                             RequestContext requestContext,
                             RoutingContext routingContext,
                             Entry entry) {
        MultipartForm multipartForm = MultipartForm.create();
        MultiMap attributes = routingContext.request()
                .formAttributes();
        attributes.forEach(attribute -> {
            multipartForm.attribute(attribute.getKey(), attribute.getValue());
        });
        routingContext.fileUploads()
                .forEach(fileUpload -> {
                    multipartForm.binaryFileUpload(fileUpload.name(), fileUpload.fileName(),
                            fileUpload.uploadedFileName(), fileUpload.contentType());
                });

        httpRequest.sendMultipartForm(multipartForm, response -> {
            handleResponse(routingContext, future, response, requestContext, entry);
        });
    }

获取以下异常

javax.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type
    at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.getMethodRouter(MethodSelectingRouter.java:478)
    at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.access[=12=]0(MethodSelectingRouter.java:94)
    at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.apply(MethodSelectingRouter.java:779)
    at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.apply(MethodSelectingRouter.java:371)

API 我下游服务的签名

@POST
    @Timed
    @Path("{userId}/{scope}/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation("Multipart upload of an image")

有人可以指导我的代码片段中有什么问题吗?或者是否有任何设置需要在 vertx 服务器或 vertx 网络客户端中启用?

谢谢, 尼蒂什·戈亚尔

我可以通过显式设置 header 来解决这个问题 .putHeader("content-type", "multipart/form-data")