我是否需要休息来回答文件并使用方法get或其他一些http方法下载它们,但我有这个错误,我将在下面介绍:
GRAVE: MessageBodyWriter not found for media type=application/octet-stream, type=class java.util.HashMap, genericType=class java.util.HashMap.
这是一个类示例,它给我同样的错误,下载任何pdf文件,但我有同样的错误。
@GET
@Path("/pdf")
public Response downloadPdfFile() {
StreamingOutput fileStream = new StreamingOutput() {
@Override
public void write(java.io.OutputStream output) throws IOException, WebApplicationException {
System.out.println("ENTRANDO!!!!");
FileInputStream fileInputStream = new FileInputStream(new File(FILE_PATH));
byte[] buffer = new byte[1024];
int count = 0;
while ((count = fileInputStream.read(buffer)) >= 0) {
output.write(buffer, 0, count);
}
output.flush();
}
};
return Response
.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM)
.header("content-disposition", "attachment; filename = myfile.pdf")
.build();
}
使用这些单位:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.22.1</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.22.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.1</version>
</dependency>
更新 我发现泽西配置中的org.glassfish.jersey.media.multipart.MultiPartFeature导致错误,但我无法删除此功能,但我上传了多部分文件 请帮忙