|
@@ -3,6 +3,7 @@ package com.jeeplus.modules.utils;
|
|
|
import com.jcraft.jsch.ChannelSftp;
|
|
|
import com.jcraft.jsch.SftpException;
|
|
|
import com.jeeplus.common.config.Global;
|
|
|
+import com.jeeplus.common.utils.StringUtils;
|
|
|
import com.jeeplus.common.web.BaseController;
|
|
|
import com.jeeplus.modules.workcontractinfo.entity.WorkContractInfo;
|
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -35,6 +36,9 @@ import java.util.regex.Pattern;
|
|
|
@RequestMapping(value = "${adminPath}/viewFile/viewFile")
|
|
|
public class ViewFileController extends BaseController {
|
|
|
|
|
|
+ /** 主机 */
|
|
|
+ private final static String host = Global.getConfig("remoteServer.host");
|
|
|
+
|
|
|
/**
|
|
|
* 返回服务器文件存储类型
|
|
|
*/
|
|
@@ -48,36 +52,34 @@ public class ViewFileController extends BaseController {
|
|
|
file = file.substring(0,file.lastIndexOf("/"));
|
|
|
file = URLDecoder.decode(file,"UTF-8");
|
|
|
|
|
|
+ InputStream in = null;
|
|
|
+ try {
|
|
|
+ if(StringUtils.isNotBlank(host) && ("127.0.0.1".equals(host) || "localhost".equals(host))){
|
|
|
+ File fileurl = new File(uploadFilePath);
|
|
|
+ in = new FileInputStream(fileurl);
|
|
|
|
|
|
- SftpClientUtil sftpClientUtil=new SftpClientUtil();
|
|
|
- try{
|
|
|
- ChannelSftp sftp = sftpClientUtil.connect();
|
|
|
- if(file != null && !"".equals(file)){
|
|
|
- sftp.cd(file);
|
|
|
+ }else{
|
|
|
+ SftpClientUtil sftpClientUtil=new SftpClientUtil();
|
|
|
+ ChannelSftp sftp = sftpClientUtil.connect();
|
|
|
+ if(file != null && !"".equals(file)){
|
|
|
+ sftp.cd(file);
|
|
|
+ }
|
|
|
+ in = sftp.get(fileName);
|
|
|
}
|
|
|
String downName = URLEncoder.encode(fileName,"UTF-8");
|
|
|
response.setContentType("application/x-download");
|
|
|
- response.setHeader("Content-disposition", "attachment; filename=" + downName);
|
|
|
- InputStream in = sftp.get(fileName);
|
|
|
+ response.addHeader("Content-Disposition" ,"attachment;filename=" +downName+ "");
|
|
|
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
|
|
|
- //创建存放文件内容的数组
|
|
|
byte[] buff =new byte[1024];
|
|
|
- //所读取的内容使用n来接收
|
|
|
int n;
|
|
|
- //当没有读取完时,继续读取,循环
|
|
|
while((n=in.read(buff))!=-1){
|
|
|
- //将字节数组的数据全部写入到输出流中
|
|
|
outputStream.write(buff,0,n);
|
|
|
}
|
|
|
- //制将缓存区的数据进行输出
|
|
|
outputStream.flush();
|
|
|
- //关流
|
|
|
outputStream.close();
|
|
|
in.close();
|
|
|
- }catch (SftpException | IOException e){
|
|
|
- logger.error("文件下载异常!", e);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.getMessage();
|
|
|
}
|
|
|
return;
|
|
|
}
|