【发布时间】:2021-07-13 00:47:37
【问题描述】:
我正在尝试设置一个允许多个文件上传以及其他表单数据的端点。将此视为创建产品页面,您将在其中拥有几张产品图片以及其他信息。理想情况下,我想将请求映射到 POJO
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Path("/product/create")
public Response createProduct(@MultipartForm CreateProductRequest req) {
还有 POJO:
@Data
public class CreateProductRequest {
@FormParam("name")
private String name;
@FormParam("description")
private String description;
@FormParam("tags")
private List<String> tags;
@FormParam("img")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
private List<InputStream> img; //Ideally I could use an object such as MultipartFile
//that would give me access to the filename and MIME type
}
但这不起作用,我明白了:
java.lang.RuntimeException: RESTEASY007545: Unable to find a MessageBodyReader for media type:
image/jpeg;charset=UTF-8 and class type java.util.List
如果我删除List,它可以正常工作。
似乎与List<String> tags 的问题相同
哪个抛出:
java.lang.RuntimeException: RESTEASY007545: Unable to find a MessageBodyReader for media
type: text/plain;charset=UTF-8 and class type java.util.List
我已经看到使用MultipartFormDataInput 的解决方法,但我真的想避免这种情况,因为请求 obj 非常大,并且手动映射它会非常乏味且容易出错。
我正在运行 Java 11,Quarkus 1.11.1.Final
非常感谢!
【问题讨论】:
标签: java file-upload resteasy quarkus