Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i send a file with jax-rs

How do send a file for download using jax-rs?

like image 902
Thiago Diniz Avatar asked Dec 07 '10 14:12

Thiago Diniz


1 Answers

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();
    }
like image 142
woddle Avatar answered Sep 17 '22 14:09

woddle