Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
543a9731
Commit
543a9731
authored
Jan 12, 2022
by
284718418@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码-修改下载BUG
parent
0a8edda1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
28 deletions
+18
-28
src/main/java/cn/timer/api/controller/disk/DiskFilesController.java
+6
-5
src/main/java/cn/timer/api/service/FtpService.java
+3
-4
src/main/java/cn/timer/api/service/impl/FtpServiceImpl.java
+9
-19
No files found.
src/main/java/cn/timer/api/controller/disk/DiskFilesController.java
View file @
543a9731
...
...
@@ -126,7 +126,7 @@ public class DiskFilesController {
}
return
ResultUtil
.
error
(
"上传文件失败"
);
}
/*
@ResponseBody
/*
@ResponseBody
@GetMapping("/download")
@ApiOperation(value = "下载普通文件", httpMethod = "POST", notes = "接口发布说明")
public Result<Object> download(@CurrentUser UserBean userBean,
...
...
@@ -140,7 +140,7 @@ public class DiskFilesController {
return ResultUtil.error("下载失败,文件不存在");
}
try {
boolean count = ftpService.downloadFile(diskFiles.getDiskPath()
,localPath,diskFiles.getTitle()+diskFiles.getFileType()
);
boolean count = ftpService.downloadFile(diskFiles.getDiskPath());
if(count){
DiskFilesLog diskFilesLog = new DiskFilesLog();
//新增 文件浏览记录
...
...
@@ -232,7 +232,7 @@ public class DiskFilesController {
if
(
StringUtils
.
isEmpty
(
diskFiles
)){
throw
new
CustomException
(
"下载失败,文件不存在"
);
}
File
InputStream
fis
=
null
;
InputStream
fis
=
null
;
BufferedInputStream
bis
=
null
;
OutputStream
os
;
File
filePath
=
null
;
...
...
@@ -241,9 +241,10 @@ public class DiskFilesController {
resp
.
setContentType
(
"application/octet-stream"
);
resp
.
setHeader
(
"content-disposition"
,
"attachment; filename="
+
new
String
(
name
.
getBytes
(
"UTF8"
),
"ISO-8859-1"
));
resp
.
setCharacterEncoding
(
"UTF-8"
);
filePath
=
new
File
(
diskFiles
.
getDiskPath
());
//
filePath = new File(diskFiles.getDiskPath());
byte
[]
buffer
=
new
byte
[
1024
];
fis
=
new
FileInputStream
(
filePath
);
// fis = new FileInputStream(filePath);
fis
=
ftpService
.
downloadFile
(
diskFiles
.
getDiskPath
());
bis
=
new
BufferedInputStream
(
fis
);
os
=
resp
.
getOutputStream
();
int
i
=
bis
.
read
(
buffer
);
...
...
src/main/java/cn/timer/api/service/FtpService.java
View file @
543a9731
...
...
@@ -5,6 +5,7 @@ import com.jcraft.jsch.ChannelSftp;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.List
;
...
...
@@ -27,11 +28,9 @@ public interface FtpService {
* 下载单个文件
*
* @param remotePath:远程目录
* @param localPath:本地保存目录
* @param localFileName:保存文件名
* @return
* @return InputStream
*/
boolean
downloadFile
(
String
remotePath
,
String
localPath
,
String
localFileName
);
InputStream
downloadFile
(
String
remotePath
);
/**
* 删除服务器文件
...
...
src/main/java/cn/timer/api/service/impl/FtpServiceImpl.java
View file @
543a9731
...
...
@@ -113,39 +113,29 @@ public class FtpServiceImpl implements FtpService {
* 下载单个文件
*
* @param remotePath:远程下载目录
* @param localPath:本地保存目录(以路径符号结束)
* @param localFileName:保存文件名
* @return
*/
@Override
public
boolean
downloadFile
(
String
remotePath
,
String
localPath
,
String
localFileName
)
{
FileOutputStream
fieloutput
=
null
;
public
InputStream
downloadFile
(
String
remotePath
)
{
ChannelSftp
sftp
=
config
.
getSftpSocket
();
InputStream
nputStream
=
null
;
try
{
// sftp.cd(remotePath);
File
file
=
new
File
(
localPath
+
localFileName
);
// mkdirs(localPath + localFileName);
fieloutput
=
new
FileOutputStream
(
file
);
sftp
.
get
(
remotePath
,
fieloutput
);
//sftp.get(remotePath, fieloutput
);
nputStream
=
sftp
.
get
(
remotePath
);
if
(
log
.
isInfoEnabled
())
{
log
.
info
(
"===DownloadFile:"
+
remotePath
+
" success from sftp."
);
}
return
true
;
}
catch
(
FileNotFound
Exception
e
)
{
return
nputStream
;
}
catch
(
Sftp
Exception
e
)
{
e
.
printStackTrace
();
}
catch
(
SftpException
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
null
!=
fieloutput
)
{
try
{
fieloutput
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
finally
{
config
.
returnSftpSocket
(
sftp
);
}
return
false
;
return
nputStream
;
}
@Override
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment