How do send a file for download using jax-rs?
Asked
Active
Viewed 1.5k times
12
-
possible duplicate of [How do I do a multipart/form file upload with jax-rs?](http://stackoverflow.com/questions/2637017/how-do-i-do-a-multipart-form-file-upload-with-jax-rs) – Bozho Dec 07 '10 at 14:24
-
11of course not, this guy want to read a uploaded file, in my case i want to send a file to download – Thiago Diniz Dec 07 '10 at 14:35
1 Answers
26
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
public Response getFile(String contentType) {
File f = new File("/tmp/file.doc");
ResponseBuilder response = Response.ok(f);
response.type(contentType);
response.header("Content-Disposition", "attachment; filename=\"file.doc\"");
return response.build();
}

Kellen Donohue
- 777
- 8
- 17

woddle
- 1,582
- 1
- 18
- 34