Merge branch 'develop_migration' into 'develop_master'
feat: There is no way the, 工作流文件下载 See merge request LiuChao/foton-slrs-system-rest!555
This commit is contained in:
+52
-15
@@ -38,6 +38,7 @@ import sun.misc.BASE64Encoder;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
@@ -77,23 +78,59 @@ public class WorkFlowController {
|
|||||||
// @RequiresPermissions("sys:file:downloadFileForSar")
|
// @RequiresPermissions("sys:file:downloadFileForSar")
|
||||||
public void downloadFileForSar(String fileId, String oldFileName, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
public void downloadFileForSar(String fileId, String oldFileName, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||||||
BusProcessModelHis modelHisOne = workFlowFeignClient.processEditFile(fileId);
|
BusProcessModelHis modelHisOne = workFlowFeignClient.processEditFile(fileId);
|
||||||
InputStream is = null;
|
|
||||||
OutputStream os = null;
|
OutputStream os = null;
|
||||||
|
// fileUrl为http或https链接
|
||||||
|
InputStream inputStream = null;
|
||||||
|
HttpURLConnection conn = null;
|
||||||
response.reset();
|
response.reset();
|
||||||
try {
|
File file = new File(downloadUrl+modelHisOne.getEditFilePath());
|
||||||
String fileOldName = fileNameEncoding(oldFileName,request);
|
|
||||||
response.setHeader("Content-Disposition", "attachment;filename=\""+fileOldName+"\"");
|
if(file.exists()){
|
||||||
response.setContentType("application/octet-stream");
|
try {
|
||||||
File file = new File(downloadUrl+modelHisOne.getEditFilePath());
|
String fileOldName = fileNameEncoding(oldFileName,request);
|
||||||
is = new FileInputStream(file);
|
response.setHeader("Content-Disposition", "attachment;filename=\""+fileOldName+"\"");
|
||||||
os = response.getOutputStream();
|
response.setContentType("application/octet-stream");
|
||||||
org.apache.commons.io.IOUtils.copy(is, os);
|
inputStream = new FileInputStream(file);
|
||||||
os.flush();
|
os = response.getOutputStream();
|
||||||
} catch (IOException e) {
|
org.apache.commons.io.IOUtils.copy(inputStream, os);
|
||||||
logger.error(e.getMessage(), e);
|
os.flush();
|
||||||
} finally {
|
} catch (IOException e) {
|
||||||
org.apache.commons.io.IOUtils.closeQuietly(is);
|
logger.error(e.getMessage(), e);
|
||||||
org.apache.commons.io.IOUtils.closeQuietly(os);
|
} finally {
|
||||||
|
org.apache.commons.io.IOUtils.closeQuietly(inputStream);
|
||||||
|
org.apache.commons.io.IOUtils.closeQuietly(os);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
URL url;
|
||||||
|
try {
|
||||||
|
String fileOldName = fileNameEncoding(oldFileName,request);
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename=\""+fileOldName+"\"");
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
url = new URL(downloadUrl+modelHisOne.getEditFilePath());
|
||||||
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
|
// 设置超时间为5秒
|
||||||
|
conn.setConnectTimeout(3 * 1000);
|
||||||
|
// 得到输入流
|
||||||
|
inputStream = conn.getInputStream();
|
||||||
|
os = response.getOutputStream();
|
||||||
|
IOUtils.copy(inputStream, os);
|
||||||
|
os.flush();
|
||||||
|
//生成本地文件之类的省略了
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
if (conn != null) {
|
||||||
|
conn.disconnect();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
IOUtils.closeQuietly(os);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user