Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
DataSwitchSys
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
数据交换平台
DataSwitchSys
Commits
ea99ebfa
提交
ea99ebfa
authored
3月 06, 2020
作者:
zhangshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
代码优化
上级
032f0c5b
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
23 行增加
和
3 行删除
+23
-3
FileDownLoadServiceImpl.java
...va/com/zjty/ftp/service/impl/FileDownLoadServiceImpl.java
+8
-0
FileUploadServiceImpl.java
...java/com/zjty/ftp/service/impl/FileUploadServiceImpl.java
+11
-3
application.properties
ds-ftp/src/main/resources/application.properties
+4
-0
没有找到文件。
ds-ftp/src/main/java/com/zjty/ftp/service/impl/FileDownLoadServiceImpl.java
浏览文件 @
ea99ebfa
package
com
.
zjty
.
ftp
.
service
.
impl
;
import
com.zjty.ftp.service.FileDownLoadService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
@@ -10,6 +11,7 @@ import java.io.*;
import
java.util.List
;
@Service
@Slf4j
public
class
FileDownLoadServiceImpl
implements
FileDownLoadService
{
@Value
(
"${file.address}"
)
...
...
@@ -26,15 +28,18 @@ public class FileDownLoadServiceImpl implements FileDownLoadService {
e
.
printStackTrace
();
}
File
sourceFile
=
new
File
(
fileAddress
);
boolean
fileExist
=
false
;
File
[]
files
=
sourceFile
.
listFiles
();
if
(
files
!=
null
&&
files
.
length
!=
0
){
for
(
File
f:
files
){
if
(
f
.
getName
().
startsWith
(
fileName
)){
fileName
=
f
.
getName
();
fileExist
=
true
;
break
;
}
}
}
if
(
fileExist
){
File
file
=
new
File
(
fileAddress
+
"/"
+
fileName
);
setFileDownloadHeader
(
httpServletRequest
,
response
,
fileName
);
OutputStream
os
=
null
;
...
...
@@ -64,6 +69,9 @@ public class FileDownLoadServiceImpl implements FileDownLoadService {
e
.
printStackTrace
();
}
}
}
else
{
log
.
info
(
"该文件不存在"
);
}
}
}
...
...
ds-ftp/src/main/java/com/zjty/ftp/service/impl/FileUploadServiceImpl.java
浏览文件 @
ea99ebfa
...
...
@@ -3,6 +3,7 @@ package com.zjty.ftp.service.impl;
import
com.zjty.ftp.service.FileUploadService
;
import
com.zjty.ftp.base.response.ServerResponse
;
import
com.zjty.ftp.entity.FileReturn
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -15,6 +16,7 @@ import java.util.List;
import
java.util.UUID
;
@Service
@Slf4j
public
class
FileUploadServiceImpl
implements
FileUploadService
{
@Value
(
"${file.address}"
)
...
...
@@ -29,6 +31,7 @@ public class FileUploadServiceImpl implements FileUploadService {
public
ServerResponse
fileUpload
(
HttpServletRequest
request
)
{
List
<
MultipartFile
>
multipartFiles
=
((
MultipartHttpServletRequest
)
request
).
getFiles
(
"file"
);
List
<
FileReturn
>
fileReturns
=
new
ArrayList
<>();
if
(
multipartFiles
!=
null
&&
multipartFiles
.
size
()
!=
0
){
for
(
MultipartFile
multipartFile:
multipartFiles
){
InputStream
is
=
null
;
BufferedInputStream
bis
=
null
;
...
...
@@ -44,9 +47,6 @@ public class FileUploadServiceImpl implements FileUploadService {
file
.
mkdirs
();
}
String
savePath
=
file
.
getAbsolutePath
()
+
"/"
+
sourceName
;
fileReturn
.
setName
(
sourceName
);
fileReturn
.
setPath
(
savePath
);
fileReturns
.
add
(
fileReturn
);
File
createFile
=
new
File
(
savePath
);
try
{
is
=
multipartFile
.
getInputStream
();
...
...
@@ -58,8 +58,12 @@ public class FileUploadServiceImpl implements FileUploadService {
while
((
len
=
bis
.
read
(
b
))
!=
-
1
){
bos
.
write
(
b
,
0
,
len
);
}
fileReturn
.
setName
(
sourceName
);
//fileReturn.setPath(savePath);
fileReturns
.
add
(
fileReturn
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
continue
;
}
finally
{
try
{
bis
.
close
();
...
...
@@ -71,6 +75,10 @@ public class FileUploadServiceImpl implements FileUploadService {
}
}
}
}
else
{
log
.
info
(
"上传失败,请重新确定key值,重新上传"
);
return
ServerResponse
.
error
(
"上传失败,请重新确定key值,重新上传"
);
}
return
ServerResponse
.
success
(
fileReturns
);
}
}
ds-ftp/src/main/resources/application.properties
浏览文件 @
ea99ebfa
...
...
@@ -5,3 +5,6 @@ spring.servlet.multipart.max-file-size=200MB
spring.servlet.multipart.max-request-size
=
200MB
file.address
=
/file/uploads
#日志文件
logging.file.path
=
./log/ds.log
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论