Spring mvc文件下载

 

 @GetMapping("/download")
    ResponseEntity<InputStreamResource> downladFile() throws IOException {

        FileSystemResource file =new FileSystemResource("H:/个人简历/s.png");
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setCacheControl("no-cache,no-store,must-revalidate");
        httpHeaders.setContentType(MediaType.IMAGE_JPEG);
        httpHeaders.setContentLength(file.contentLength());
        httpHeaders.setContentDispositionFormData("attachment", URLEncoder.encode("妹妹.jpg","utf-8"));
        return ResponseEntity.ok()
                .headers(httpHeaders)
                .body(new InputStreamResource(file.getInputStream()));
    }

 

posted @ 2018-11-12 10:17  韦邦杠  阅读(166)  评论(0编辑  收藏  举报