如何在泽西中使用MediaType类创建自定义mime类型? 以下是我的代码:
public class MimeTypeClass extends MediaType {
public static final String APPLICATION_IMAGE_JPEG = "image/jpeg";
}
当我构建正文时,我收到编译错误:
FormDataBodyPart bodyPart1 = new FormDataBodyPart(
FormDataContentDisposition.name("Thumbnail").fileName("thumbnail").build(),
inputStreamThumbNail, MimeTypeClass.APPLICATION_IMAGE_JPEG);
答案 0 :(得分:1)
您传递的是String,而不是MediaType。自定义媒体类型的包装器可能如下所示:
public class CustomMediaTypes {
public final static String IMAGE_JPEG = "image/jpeg";
public final static MediaType IMAGE_JPEG_TYPE = new MediaType("image", "jpeg");
}
然后,您可以将CustomMediaTypes.IMAGE_JPEG_TYPE
传递给FormDataBodyPart
构造函数,将CustomMediaTypes.IMAGE_JPEG
传递给@Consumes
注释