Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-parent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 7cc6d569
authored
May 08, 2021
by
zhoujinghao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
上传下载相关代码提交
1 parent
15251a0a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
31 deletions
nafmii-admin/src/main/java/org/nafmii/admin/att/controller/AttController.java
nafmii-admin/src/main/java/org/nafmii/admin/att/service/AttService.java
nafmii-admin/src/main/java/org/nafmii/admin/att/service/impl/AttServiceImpl.java
nafmii-admin/src/main/java/org/nafmii/admin/att/controller/AttController.java
View file @
7cc6d56
...
...
@@ -30,16 +30,14 @@ public class AttController {
@Autowired
private
AttService
attService
;
/**
*
* @name: uploadToFtp
* @description: 上传文件到ftp
* @params: []
* @return: java.lang.String
* @date: 2019/12/18 15:48
* @auther:
/**上传文件到ftp
*
**/
* @param description 描述
* @param userId 用户id
* @param files 文件
* @return
*/
@ApiOperation
(
value
=
"上传文件到ftp"
,
notes
=
"上传文件到ftp"
)
@PostMapping
(
value
=
"/uploadToFtp"
,
headers
=
"content-type=multipart/form-data"
)
@ResponseBody
...
...
@@ -55,13 +53,18 @@ public class AttController {
/**
* 下载ftp上文件到本地
* @return
*@param newFileName 新文件名
*@param fileName 原文件(路径+文件名)
*@param downUrl 下载路径
*@return
*/
@ApiOperation
(
value
=
"下载ftp上文件到本地"
,
notes
=
"下载ftp上文件到本地"
)
@PostMapping
(
value
=
"/downloadFile"
,
headers
=
"content-type=multipart/form-data"
)
@ResponseBody
public
ApiResponse
downloadFile
(
@RequestParam
(
"files"
)
@Validated
MultipartFile
[]
files
)
{
ApiResponse
apiResponse
=
attService
.
downloadFile
(
files
);
public
ApiResponse
downloadFile
(
@RequestParam
(
"newFileName"
)
String
newFileName
,
@RequestParam
(
"fileName"
)
String
fileName
,
@RequestParam
(
"downUrl"
)
String
downUrl
)
{
ApiResponse
apiResponse
=
attService
.
downloadFile
(
newFileName
,
fileName
,
downUrl
);
return
apiResponse
;
}
}
...
...
nafmii-admin/src/main/java/org/nafmii/admin/att/service/AttService.java
View file @
7cc6d56
...
...
@@ -17,7 +17,7 @@ import java.util.List;
*/
public
interface
AttService
{
//下载ftp上文件到本地
ApiResponse
downloadFile
(
MultipartFile
[]
files
);
ApiResponse
downloadFile
(
String
newFileName
,
String
fileName
,
String
downUrl
);
//上传文件到ftp
ApiResponse
uploadToFtp
(
MultipartFile
[]
files
,
String
description
,
Long
userId
);
...
...
nafmii-admin/src/main/java/org/nafmii/admin/att/service/impl/AttServiceImpl.java
View file @
7cc6d56
...
...
@@ -24,9 +24,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.*
;
import
java.util.*
;
/**
...
...
@@ -53,22 +51,35 @@ public class AttServiceImpl implements AttService {
private
AttachmentInfoMapper
infoMapper
;
/**
* 下载ftp上文件到本地
* @return
*@param newFileName 新文件名
*@param fileName 原文件(路径+文件名)
*@param downUrl 下载路径
*@return
*/
@Override
public
ApiResponse
downloadFile
(
MultipartFile
[]
files
)
{
// for (MultipartFile file:files) {
// FtpOperationUtils ftpOperationUtils = new FtpOperationUtils();
// try {
// String originalFilename = file.getOriginalFilename();
// InputStream inputStream = ftpOperationUtils.downloadFile(originalFilename);
// FileUtil.writeFromStream(inputStream, "D:\\a1.txt");
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
return
null
;
public
ApiResponse
downloadFile
(
String
newFileName
,
String
fileName
,
String
downUrl
)
{
log
.
info
(
"下载文件参数newFileName:{}fileName:{}downUrl:"
,
newFileName
,
fileName
,
downUrl
);
OutputStream
os
=
null
;
String
lastPath
=
""
;
File
localFile
=
new
File
(
downUrl
+
"/"
+
newFileName
);
if
(!
localFile
.
getParentFile
().
exists
()){
//文件夹目录不存在创建目录
localFile
.
getParentFile
().
mkdirs
();
//存放图片的路径地址
StringBuilder
sb
=
new
StringBuilder
(
ftpPath
).
append
(
"/"
);
String
path
=
sb
.
toString
();
lastPath
=
path
;
try
{
localFile
.
createNewFile
();
os
=
new
FileOutputStream
(
localFile
);
FtpUtil
fileFtp
=
new
FtpUtil
();
log
.
info
(
"通过ftp下载文件参数lastPath:{}ileName:{}downUrl:"
,
lastPath
,
fileName
,
downUrl
);
fileFtp
.
downloadFile
(
lastPath
,
fileName
,
downUrl
);
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
new
ApiResponse
(
ApiResponse
.
SUCCESS
,
ApiResponse
.
SUCCESS_TEXT
);
}
/**
...
...
@@ -99,7 +110,7 @@ public class AttServiceImpl implements AttService {
if
(!
extList
.
contains
(
suffixes
))
{
return
new
ApiResponse
(
ApiResponse
.
FAIL
,
MessageEnum
.
FILE_PICTURE
.
getRemarks
());
}
//
图片名称
重新命名包括后缀名
//重新命名包括后缀名
String
newName
=
StringUtil
.
getRandomOrderNumber
()
+
"_"
+
StringUtil
.
getRandomOrderNumberString
()
+
suffixes
;
// String newName= UUID.randomUUID().toString().replaceAll("\\-", "")+suffixes;
newNameList
.
add
(
newName
);
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment