Why is MIME media type application/zip not found?
Asked Answered
O

3

7

I need to return zip file in my rest Api but i receive MIME media type application/zip was not found.

@Produces({ "application/zip" })
    public Response convertFile(){
    .
    .
    .
    return Response.ok(result, "application/zip").build();
} 
Oneidaoneil answered 14/9, 2015 at 18:37 Comment(1)
You need to create your own MessageBodyWriter for application/zip and the Java type or just use application/octect-streamPalikar
W
5

Try this:

@Produces("application/zip")

 return Response
            .ok(FileUtils.readFileToByteArray(resultFile))
            .type("application/zip")
            .header("Content-Disposition", "attachment; filename=\"yourfile.zip\"")
            .build();
Wizard answered 14/9, 2015 at 18:52 Comment(0)
D
1

Use MediaType#MULTIPART_FORM_DATA_TYPE.

read: http://docs.oracle.com/javaee/6/api/javax/ws/rs/core/MediaType.html#MULTIPART_FORM_DATA

Dialectology answered 14/9, 2015 at 19:56 Comment(0)
G
0

You can simply do this too.

@Produces("application/zip")
public File getAZipFile(){
 //your controller code which returns a file
    return file;
}

Note: Accept headers must be application/zip

Gigue answered 29/11, 2020 at 11:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.