We are working on download file from browser in my html angularjs spring integration application, the application was not completely in spring.
I am trying to download file using the code :
import java.io.File;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
@Path("/downloadfiles")
public class RestfulFiledownloadExample {
private static final String path = "c:\\log.txt";
@GET
@Path("/downloadtxt")
@Produces("text/plain")
public Response getFile() {
File file = new File(path);
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition","attachment; filename=\"newfile.txt\"");
return response.build();
}
}
But it downloading file with 1 KB in size. How can I solve the issue to download the file without corrupting it?