如何从REST服务获取文件内容类型?
我有一个REST服务来上传文件,有没有办法知道我可能会得到什么内容类型?使用我的REST服务的用户可能会上载PDF、Word或Excel文档如何从REST服务获取文件内容类型?,rest,jersey,dropwizard,Rest,Jersey,Dropwizard,我有一个REST服务来上传文件,有没有办法知道我可能会得到什么内容类型?使用我的REST服务的用户可能会上载PDF、Word或Excel文档 @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/details/documents") public Response uploadDocument(@FormDataParam("file") File documentContent,
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/details/documents")
public Response uploadDocument(@FormDataParam("file") File documentContent,
@FormDataParam("documentName") String documentName)
throws Exception {
//more implementation code here to upload the file.
}
您可以使用
FormDataBodyPart
,然后调用getMediaType()
,而不是将File
作为方法参数。如果您想将零件的主体作为文件
,只需使用getValueAs(File.class)
,或者如果您想要输入流,只需使用InputStream.class
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/details/documents")
public Response uploadDocument(@FormDataParam("file") FormDataBodyPart part) {
MediaType mediaType = part.getMediaType();
File file = part.getValueAs(File.class);
}