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.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
@@ -77,23 +78,59 @@ public class WorkFlowController {
|
||||
// @RequiresPermissions("sys:file:downloadFileForSar")
|
||||
public void downloadFileForSar(String fileId, String oldFileName, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||||
BusProcessModelHis modelHisOne = workFlowFeignClient.processEditFile(fileId);
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
// fileUrl为http或https链接
|
||||
InputStream inputStream = null;
|
||||
HttpURLConnection conn = null;
|
||||
response.reset();
|
||||
try {
|
||||
String fileOldName = fileNameEncoding(oldFileName,request);
|
||||
response.setHeader("Content-Disposition", "attachment;filename=\""+fileOldName+"\"");
|
||||
response.setContentType("application/octet-stream");
|
||||
File file = new File(downloadUrl+modelHisOne.getEditFilePath());
|
||||
is = new FileInputStream(file);
|
||||
os = response.getOutputStream();
|
||||
org.apache.commons.io.IOUtils.copy(is, os);
|
||||
os.flush();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
org.apache.commons.io.IOUtils.closeQuietly(is);
|
||||
org.apache.commons.io.IOUtils.closeQuietly(os);
|
||||
File file = new File(downloadUrl+modelHisOne.getEditFilePath());
|
||||
|
||||
if(file.exists()){
|
||||
try {
|
||||
String fileOldName = fileNameEncoding(oldFileName,request);
|
||||
response.setHeader("Content-Disposition", "attachment;filename=\""+fileOldName+"\"");
|
||||
response.setContentType("application/octet-stream");
|
||||
inputStream = new FileInputStream(file);
|
||||
os = response.getOutputStream();
|
||||
org.apache.commons.io.IOUtils.copy(inputStream, os);
|
||||
os.flush();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} 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