0

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?

Neelam Sharma
  • 2,745
  • 4
  • 32
  • 73
  • Take a look: https://stackoverflow.com/questions/32995666/spring-rest-and-jquery-ajax-file-download – Rana_S Jun 23 '17 at 14:43
  • I tried this... But my HttpServletResponse is null, so I could not process with this. As my controller is not RestController.. Its spring integrated project not complete spring. – Neelam Sharma Jun 25 '17 at 23:44

0 Answers0