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
b1c0c13f
Commit
b1c0c13f
authored
Feb 22, 2023
by
284718418@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件存储地址配置切换
parent
d949cd0b
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
154 additions
and
22 deletions
+154
-22
src/main/java/cn/timer/api/config/sftp/SftpConfiguration.java
+9
-0
src/main/java/cn/timer/api/controller/disk/DiskFilesController.java
+8
-5
src/main/java/cn/timer/api/controller/disk/constant/FileAddressConstant.java
+22
-0
src/main/java/cn/timer/api/service/FtpService.java
+3
-2
src/main/java/cn/timer/api/service/OSSService.java
+41
-0
src/main/java/cn/timer/api/service/impl/FtpServiceImpl.java
+34
-15
src/main/java/cn/timer/api/service/impl/OSSServiceImpl.java
+8
-0
src/main/java/cn/timer/api/utils/aliyun/OSSUtil.java
+21
-0
src/main/resources/application-pro.yml
+8
-0
No files found.
src/main/java/cn/timer/api/config/sftp/SftpConfiguration.java
View file @
b1c0c13f
...
@@ -53,6 +53,15 @@ public class SftpConfiguration {
...
@@ -53,6 +53,15 @@ public class SftpConfiguration {
@Value
(
"${sftp.client.serverUrl}"
)
@Value
(
"${sftp.client.serverUrl}"
)
private
String
serverUrl
;
private
String
serverUrl
;
@Value
(
"${sftp.client.targetPath}"
)
private
String
targetPath
;
@Value
(
"${sftp.client.reservedName}"
)
private
boolean
reservedName
;
@Value
(
"${config-8timer.file-address.type}"
)
public
String
fileAddress
;
/**
/**
* @Title: getSftpSocket
* @Title: getSftpSocket
* @Description: 获取连接
* @Description: 获取连接
...
...
src/main/java/cn/timer/api/controller/disk/DiskFilesController.java
View file @
b1c0c13f
...
@@ -13,6 +13,7 @@ import cn.timer.api.config.sftp.SftpConfiguration;
...
@@ -13,6 +13,7 @@ import cn.timer.api.config.sftp.SftpConfiguration;
import
cn.timer.api.controller.disk.sevice.DiskFilesService
;
import
cn.timer.api.controller.disk.sevice.DiskFilesService
;
import
cn.timer.api.dto.disk.*
;
import
cn.timer.api.dto.disk.*
;
import
cn.timer.api.service.FtpService
;
import
cn.timer.api.service.FtpService
;
import
cn.timer.api.service.OSSService
;
import
cn.timer.api.utils.FileUtils
;
import
cn.timer.api.utils.FileUtils
;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.ResultUtil
;
import
cn.timer.api.utils.ResultUtil
;
...
@@ -59,8 +60,8 @@ public class DiskFilesController {
...
@@ -59,8 +60,8 @@ public class DiskFilesController {
@Autowired
@Autowired
private
DiskFilesService
diskFilesService
;
private
DiskFilesService
diskFilesService
;
@
Value
(
"${sftp.client.root}"
)
@
Autowired
private
S
tring
root
;
private
S
ftpConfiguration
config
;
@Value
(
"${sftp.client.targetPath}"
)
@Value
(
"${sftp.client.targetPath}"
)
private
String
targetPath
;
private
String
targetPath
;
...
@@ -70,6 +71,8 @@ public class DiskFilesController {
...
@@ -70,6 +71,8 @@ public class DiskFilesController {
@Value
(
"${sftp.client.serverUrl}"
)
@Value
(
"${sftp.client.serverUrl}"
)
private
String
serverUrl
;
private
String
serverUrl
;
@Autowired
private
OSSService
ossService
;
@ResponseBody
@ResponseBody
...
@@ -112,12 +115,12 @@ public class DiskFilesController {
...
@@ -112,12 +115,12 @@ public class DiskFilesController {
List
<
FileInfoDto
>
imageUrls
;
List
<
FileInfoDto
>
imageUrls
;
try
{
try
{
//上传文件到服务器
//上传文件到服务器
imageUrls
=
ftpService
.
uploadFile
(
targetPath
,
file
,
reservedNam
e
);
imageUrls
=
ftpService
.
uploadFile
(
userBean
.
getOrgCode
(),
fil
e
);
for
(
FileInfoDto
dto
:
imageUrls
)
{
for
(
FileInfoDto
dto
:
imageUrls
)
{
//新增资源上传文件
//新增资源上传文件
diskFiles
.
setFileType
(
dto
.
getFileSuffix
());
diskFiles
.
setFileType
(
dto
.
getFileSuffix
());
//"/home/disk/123456.jpg"
//"/home/disk/123456.jpg"
diskFiles
.
setDiskPath
(
root
+
targetPath
+
"/"
+
dto
.
getFileName
());
diskFiles
.
setDiskPath
(
dto
.
getFileName
());
diskFiles
.
setUrlPath
(
dto
.
getUrlPath
());
diskFiles
.
setUrlPath
(
dto
.
getUrlPath
());
diskFiles
.
setTitle
(
dto
.
getResourceFileName
());
diskFiles
.
setTitle
(
dto
.
getResourceFileName
());
diskFiles
.
setFileSize
(
dto
.
getFileSize
());
diskFiles
.
setFileSize
(
dto
.
getFileSize
());
...
@@ -269,7 +272,7 @@ public class DiskFilesController {
...
@@ -269,7 +272,7 @@ public class DiskFilesController {
// filePath = new File(diskFiles.getDiskPath());
// filePath = new File(diskFiles.getDiskPath());
byte
[]
buffer
=
new
byte
[
1024
];
byte
[]
buffer
=
new
byte
[
1024
];
// fis = new FileInputStream(filePath);
// fis = new FileInputStream(filePath);
fis
=
ftpService
.
downloadFile
(
diskFiles
.
getDiskPath
()
);
fis
=
ftpService
.
downloadFile
(
diskFiles
);
bis
=
new
BufferedInputStream
(
fis
);
bis
=
new
BufferedInputStream
(
fis
);
os
=
resp
.
getOutputStream
();
os
=
resp
.
getOutputStream
();
int
i
=
bis
.
read
(
buffer
);
int
i
=
bis
.
read
(
buffer
);
...
...
src/main/java/cn/timer/api/controller/disk/constant/FileAddressConstant.java
0 → 100644
View file @
b1c0c13f
package
cn
.
timer
.
api
.
controller
.
disk
.
constant
;
/**
* 文件存储地址常量
*
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022-04-02 11:05:49
*/
public
class
FileAddressConstant
{
/**
* aliyun-oss(阿里云OSS)
*/
public
static
final
String
ALIYUN_OSS
=
"aliyun-oss"
;
/**
* physics-oss(物理机器OSS)
*/
public
static
final
String
PHYSICS_OSS
=
"physics-oss"
;
}
\ No newline at end of file
src/main/java/cn/timer/api/service/FtpService.java
View file @
b1c0c13f
package
cn
.
timer
.
api
.
service
;
package
cn
.
timer
.
api
.
service
;
import
cn.timer.api.bean.disk.DiskFiles
;
import
cn.timer.api.dto.disk.FileInfoDto
;
import
cn.timer.api.dto.disk.FileInfoDto
;
import
com.jcraft.jsch.ChannelSftp
;
import
com.jcraft.jsch.ChannelSftp
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -23,14 +24,14 @@ public interface FtpService {
...
@@ -23,14 +24,14 @@ public interface FtpService {
* @param reservedName
* @param reservedName
* @return
* @return
*/
*/
List
<
FileInfoDto
>
uploadFile
(
String
targetPath
,
MultipartFile
[]
files
,
boolean
reservedName
);
List
<
FileInfoDto
>
uploadFile
(
int
orgCode
,
MultipartFile
[]
files
);
/**
/**
* 下载单个文件
* 下载单个文件
*
*
* @param remotePath:远程目录
* @param remotePath:远程目录
* @return InputStream
* @return InputStream
*/
*/
InputStream
downloadFile
(
String
remotePath
);
InputStream
downloadFile
(
DiskFiles
diskFiles
);
/**
/**
* 删除服务器文件
* 删除服务器文件
...
...
src/main/java/cn/timer/api/service/OSSService.java
View file @
b1c0c13f
package
cn
.
timer
.
api
.
service
;
package
cn
.
timer
.
api
.
service
;
import
cn.timer.api.dto.disk.FileInfoDto
;
import
cn.timer.api.service.impl.OSSServiceImpl
;
import
cn.timer.api.service.impl.OSSServiceImpl
;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.ResultUtil
;
import
cn.timer.api.utils.ResultUtil
;
...
@@ -11,6 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -11,6 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.locks.ReentrantLock
;
import
java.util.concurrent.locks.ReentrantLock
;
...
@@ -86,4 +88,43 @@ public class OSSService implements OSSServiceImpl {
...
@@ -86,4 +88,43 @@ public class OSSService implements OSSServiceImpl {
}
}
return
ResultUtil
.
data
(
list
,
"上传成功!"
);
return
ResultUtil
.
data
(
list
,
"上传成功!"
);
}
}
@Override
public
List
<
FileInfoDto
>
uploadFile
(
int
orgCode
,
String
moudle
,
MultipartFile
[]
files
)
{
List
<
FileInfoDto
>
resultStrs
=
new
ArrayList
<
FileInfoDto
>();
FileInfoDto
dto
=
null
;
for
(
MultipartFile
file
:
files
)
{
String
randomNickname
=
RandomNum
.
getRandomNickname
();
String
name
=
file
.
getOriginalFilename
().
substring
(
0
,
file
.
getOriginalFilename
().
lastIndexOf
(
"."
));
String
suffix
=
file
.
getOriginalFilename
().
substring
(
file
.
getOriginalFilename
().
lastIndexOf
(
"."
));
File
filePath
=
filePathUpload
(
orgCode
,
moudle
,
randomNickname
,
file
.
getOriginalFilename
());
int
i
=
0
;
while
(
filePath
.
exists
())
{
filePath
=
filePathUpload
(
orgCode
,
moudle
,
randomNickname
,
file
.
getOriginalFilename
());
i
++;
}
if
(
file
==
null
||
file
.
getSize
()
<=
0
)
{
// return ResultUtil.error("上传的文件为空,请重新选择!");
}
else
{
try
{
dto
=
new
FileInfoDto
();
dto
.
setUrlPath
(
oss
.
uploadFile
(
filePath
,
file
.
getInputStream
()));
dto
.
setResourceFileName
(
name
);
dto
.
setFileName
(
filePath
.
getPath
());
/*Float size = Float.parseFloat(String.valueOf(file.getSize())) / 1024;
BigDecimal b = new BigDecimal(size);
// 2表示2位 ROUND_HALF_UP表明四舍五入,
size = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();*/
dto
.
setFileSize
(
file
.
getSize
());
dto
.
setFileSuffix
(
suffix
);
resultStrs
.
add
(
dto
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
resultStrs
;
}
}
}
src/main/java/cn/timer/api/service/impl/FtpServiceImpl.java
View file @
b1c0c13f
package
cn
.
timer
.
api
.
service
.
impl
;
package
cn
.
timer
.
api
.
service
.
impl
;
import
cn.timer.api.bean.disk.DiskFiles
;
import
cn.timer.api.config.sftp.SftpConfiguration
;
import
cn.timer.api.config.sftp.SftpConfiguration
;
import
cn.timer.api.controller.disk.constant.FileAddressConstant
;
import
cn.timer.api.dto.disk.FileInfoDto
;
import
cn.timer.api.dto.disk.FileInfoDto
;
import
cn.timer.api.service.FtpService
;
import
cn.timer.api.service.FtpService
;
import
cn.timer.api.service.OSSService
;
import
cn.timer.api.utils.Md5
;
import
cn.timer.api.utils.Md5
;
import
cn.timer.api.utils.aliyun.OSSUtil
;
import
com.jcraft.jsch.ChannelSftp
;
import
com.jcraft.jsch.ChannelSftp
;
import
com.jcraft.jsch.SftpException
;
import
com.jcraft.jsch.SftpException
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -26,6 +30,10 @@ public class FtpServiceImpl implements FtpService {
...
@@ -26,6 +30,10 @@ public class FtpServiceImpl implements FtpService {
@Autowired
@Autowired
private
SftpConfiguration
config
;
private
SftpConfiguration
config
;
@Autowired
private
OSSUtil
oss
;
@Autowired
private
OSSService
ossService
;
@Override
@Override
...
@@ -63,15 +71,18 @@ public class FtpServiceImpl implements FtpService {
...
@@ -63,15 +71,18 @@ public class FtpServiceImpl implements FtpService {
@Async
(
"threadPoolTaskExecutor"
)
@Async
(
"threadPoolTaskExecutor"
)
@Override
@Override
public
List
<
FileInfoDto
>
uploadFile
(
String
targetPath
,
MultipartFile
[]
files
,
boolean
reservedName
)
{
public
List
<
FileInfoDto
>
uploadFile
(
int
orgCode
,
MultipartFile
[]
files
)
{
ChannelSftp
sftp
=
config
.
getSftpSocket
();
List
<
FileInfoDto
>
resultStrs
=
new
ArrayList
<
FileInfoDto
>();
List
<
FileInfoDto
>
resultStrs
=
new
ArrayList
<
FileInfoDto
>();
//存储地址判断
if
(
FileAddressConstant
.
PHYSICS_OSS
.
equals
(
config
.
getFileAddress
()))
{
ChannelSftp
sftp
=
config
.
getSftpSocket
();
try
{
try
{
sftp
.
cd
(
config
.
getRoot
());
sftp
.
cd
(
config
.
getRoot
());
//log.info("sftp连接host", config.getRoot());
//log.info("sftp连接host", config.getRoot());
boolean
dirs
=
this
.
createDirs
(
targetPath
,
sftp
);
boolean
dirs
=
this
.
createDirs
(
config
.
getTargetPath
()
,
sftp
);
if
(!
dirs
)
{
if
(!
dirs
)
{
log
.
error
(
"sftp创建目录失败"
,
targetPath
);
log
.
error
(
"sftp创建目录失败"
,
config
.
getTargetPath
()
);
throw
new
RuntimeException
(
"上传文件失败"
);
throw
new
RuntimeException
(
"上传文件失败"
);
}
}
FileInfoDto
dto
=
null
;
FileInfoDto
dto
=
null
;
...
@@ -80,7 +91,7 @@ public class FtpServiceImpl implements FtpService {
...
@@ -80,7 +91,7 @@ public class FtpServiceImpl implements FtpService {
String
fileName
=
""
;
String
fileName
=
""
;
String
name
=
file
.
getOriginalFilename
().
substring
(
0
,
file
.
getOriginalFilename
().
lastIndexOf
(
"."
));
String
name
=
file
.
getOriginalFilename
().
substring
(
0
,
file
.
getOriginalFilename
().
lastIndexOf
(
"."
));
String
suffix
=
file
.
getOriginalFilename
().
substring
(
file
.
getOriginalFilename
().
lastIndexOf
(
"."
));
String
suffix
=
file
.
getOriginalFilename
().
substring
(
file
.
getOriginalFilename
().
lastIndexOf
(
"."
));
if
(
reservedName
)
{
if
(
config
.
isReservedName
()
)
{
fileName
=
Md5
.
md5
(
name
+
UUID
.
randomUUID
().
toString
())
+
suffix
;
fileName
=
Md5
.
md5
(
name
+
UUID
.
randomUUID
().
toString
())
+
suffix
;
}
else
{
}
else
{
fileName
=
UUID
.
randomUUID
().
toString
()
+
suffix
;
fileName
=
UUID
.
randomUUID
().
toString
()
+
suffix
;
...
@@ -88,7 +99,7 @@ public class FtpServiceImpl implements FtpService {
...
@@ -88,7 +99,7 @@ public class FtpServiceImpl implements FtpService {
sftp
.
put
(
file
.
getInputStream
(),
fileName
);
sftp
.
put
(
file
.
getInputStream
(),
fileName
);
dto
.
setUrlPath
(
config
.
getServerUrl
()
+
"/"
+
fileName
);
dto
.
setUrlPath
(
config
.
getServerUrl
()
+
"/"
+
fileName
);
dto
.
setResourceFileName
(
name
);
dto
.
setResourceFileName
(
name
);
dto
.
setFileName
(
fileName
);
dto
.
setFileName
(
config
.
getRoot
()
+
config
.
getTargetPath
()
+
"/"
+
fileName
);
/*Float size = Float.parseFloat(String.valueOf(file.getSize())) / 1024;
/*Float size = Float.parseFloat(String.valueOf(file.getSize())) / 1024;
BigDecimal b = new BigDecimal(size);
BigDecimal b = new BigDecimal(size);
...
@@ -101,12 +112,15 @@ public class FtpServiceImpl implements FtpService {
...
@@ -101,12 +112,15 @@ public class FtpServiceImpl implements FtpService {
}
}
return
resultStrs
;
return
resultStrs
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"上传文件失败"
,
targetPath
,
e
);
e
.
printStackTrace
();
e
.
printStackTrace
();
throw
new
RuntimeException
(
"上传文件失败"
);
throw
new
RuntimeException
(
"上传文件失败"
);
}
finally
{
}
finally
{
config
.
returnSftpSocket
(
sftp
);
config
.
returnSftpSocket
(
sftp
);
}
}
}
else
if
(
FileAddressConstant
.
ALIYUN_OSS
.
equals
(
config
.
getFileAddress
()))
{
resultStrs
=
ossService
.
uploadFile
(
orgCode
,
"disk"
,
files
);
}
return
resultStrs
;
}
}
...
@@ -114,29 +128,34 @@ public class FtpServiceImpl implements FtpService {
...
@@ -114,29 +128,34 @@ public class FtpServiceImpl implements FtpService {
/**
/**
* 下载单个文件
* 下载单个文件
*
*
* @param
remotePath
:远程下载目录
* @param
diskFiles
:远程下载目录
* @return
* @return
*/
*/
@Override
@Override
public
InputStream
downloadFile
(
String
remotePath
)
{
public
InputStream
downloadFile
(
DiskFiles
diskFiles
)
{
ChannelSftp
sftp
=
config
.
getSftpSocket
();
//存储地址判断
InputStream
nputStream
=
null
;
InputStream
nputStream
=
null
;
if
(
diskFiles
.
getUrlPath
().
indexOf
(
config
.
getServerUrl
())!=-
1
)
{
ChannelSftp
sftp
=
config
.
getSftpSocket
();
try
{
try
{
// sftp.cd(remotePath);
// sftp.cd(remotePath);
// mkdirs(localPath + localFileName);
// mkdirs(localPath + localFileName);
//sftp.get(remotePath, fieloutput);
//sftp.get(remotePath, fieloutput);
nputStream
=
sftp
.
get
(
remotePath
);
nputStream
=
sftp
.
get
(
diskFiles
.
getDiskPath
()
);
if
(
log
.
isInfoEnabled
())
{
if
(
log
.
isInfoEnabled
())
{
log
.
info
(
"===DownloadFile:"
+
remotePath
+
" success from sftp."
);
log
.
info
(
"===DownloadFile:"
+
diskFiles
.
getDiskPath
()
+
" success from sftp."
);
}
}
return
nputStream
;
return
nputStream
;
}
catch
(
SftpException
e
)
{
}
catch
(
SftpException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
config
.
returnSftpSocket
(
sftp
);
config
.
returnSftpSocket
(
sftp
);
}
}
}
else
if
(
FileAddressConstant
.
ALIYUN_OSS
.
equals
(
config
.
getFileAddress
()))
{
nputStream
=
oss
.
downloadFileInputStream
(
diskFiles
.
getDiskPath
());
}
return
nputStream
;
return
nputStream
;
}
}
...
...
src/main/java/cn/timer/api/service/impl/OSSServiceImpl.java
View file @
b1c0c13f
package
cn
.
timer
.
api
.
service
.
impl
;
package
cn
.
timer
.
api
.
service
.
impl
;
import
cn.timer.api.dto.disk.FileInfoDto
;
import
cn.timer.api.utils.Result
;
import
cn.timer.api.utils.Result
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.InputStream
;
import
java.util.List
;
import
java.util.List
;
public
interface
OSSServiceImpl
{
public
interface
OSSServiceImpl
{
public
Result
<
String
>
upload
(
int
orgCode
,
String
moudle
,
MultipartFile
file
);
public
Result
<
String
>
upload
(
int
orgCode
,
String
moudle
,
MultipartFile
file
);
public
Result
<
Object
>
uploads
(
int
orgCode
,
String
moudle
,
List
<
MultipartFile
>
files
);
public
Result
<
Object
>
uploads
(
int
orgCode
,
String
moudle
,
List
<
MultipartFile
>
files
);
/**
* 上传文件到阿里云服务器
* @param files
* @return
*/
List
<
FileInfoDto
>
uploadFile
(
int
orgCode
,
String
moudle
,
MultipartFile
[]
files
);
}
}
src/main/java/cn/timer/api/utils/aliyun/OSSUtil.java
View file @
b1c0c13f
...
@@ -8,11 +8,15 @@ import java.util.*;
...
@@ -8,11 +8,15 @@ import java.util.*;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
java.util.zip.ZipOutputStream
;
import
cn.timer.api.config.sftp.SftpConfiguration
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
import
com.jcraft.jsch.ChannelSftp
;
import
io.swagger.models.auth.In
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.bouncycastle.jce.exception.ExtIOException
;
import
org.bouncycastle.jce.exception.ExtIOException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -77,6 +81,11 @@ public class OSSUtil {
...
@@ -77,6 +81,11 @@ public class OSSUtil {
@Value
(
"${zip.path}"
)
@Value
(
"${zip.path}"
)
private
String
zipPath
;
private
String
zipPath
;
@Autowired
private
SftpConfiguration
config
;
/**
/**
* 1.创建储存空间 sout控制台輸出 储存空间名
* 1.创建储存空间 sout控制台輸出 储存空间名
*
*
...
@@ -238,6 +247,18 @@ public class OSSUtil {
...
@@ -238,6 +247,18 @@ public class OSSUtil {
return
ResultUtil
.
data
(
reader
,
"下载成功"
);
return
ResultUtil
.
data
(
reader
,
"下载成功"
);
}
}
public
InputStream
downloadFileInputStream
(
String
objectName
)
{
// 创建OSSClient实例。
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
OSSObject
ossObject
=
ossClient
.
getObject
(
bucketName
,
objectName
);
// 关闭OSSClient。
//ossClient.shutdown();
return
ossObject
.
getObjectContent
();
}
/**
/**
* 文件输入流批量上传
* 文件输入流批量上传
*
*
...
...
src/main/resources/application-pro.yml
View file @
b1c0c13f
...
@@ -207,6 +207,14 @@ config-8timer:
...
@@ -207,6 +207,14 @@ config-8timer:
crm-excel
:
crm-excel
:
realPath
:
'
/data/crm-excel/'
realPath
:
'
/data/crm-excel/'
# 文件存储地址配置 file type:aliyun-oss,physics-oss
# 文件存储地址类型:aliyun-oss(阿里云OSS),physics-oss(物理机器OSS)
# 默认存储物理机器OSS
file-address
:
#type: physics-oss
type
:
aliyun-oss
#导出zip临时地址
#导出zip临时地址
zip
:
zip
:
path
:
'
/data/crm-zip/'
path
:
'
/data/crm-zip/'
...
...
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