1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.demo.uif.controller;
17
18 import org.kuali.rice.krad.file.FileMeta;
19 import org.kuali.rice.krad.file.FileMetaBlob;
20 import org.kuali.rice.krad.web.form.UifFormBase;
21 import org.kuali.rice.krad.web.service.impl.FileControllerServiceImpl;
22 import org.springframework.util.FileCopyUtils;
23
24 import javax.servlet.http.HttpServletResponse;
25 import java.io.InputStream;
26 import java.util.List;
27
28
29
30
31
32
33 public class DemoFileControllerServiceImpl extends FileControllerServiceImpl {
34
35
36
37
38 @Override
39 protected void sendFileFromLineResponse(UifFormBase form, HttpServletResponse response, List<FileMeta> collection,
40 FileMeta fileLine) {
41 if (!(fileLine instanceof FileMetaBlob)) {
42 return;
43 }
44
45 try {
46 InputStream is = ((FileMetaBlob) fileLine).getBlob().getBinaryStream();
47 response.setContentType(fileLine.getContentType());
48 response.setHeader("Content-Disposition", "attachment; filename=" + fileLine.getName());
49
50
51 FileCopyUtils.copy(is, response.getOutputStream());
52
53 response.flushBuffer();
54 } catch (Exception e) {
55 throw new RuntimeException("Unable to get file contents", e);
56 }
57 }
58 }