Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
cfld-region-outline
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cfld-backend
cfld-region-outline
Commits
fe3fbb34
Commit
fe3fbb34
authored
Jan 05, 2024
by
yaobaizheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片压缩异步删除
parent
a1b1de7a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
2 deletions
+38
-2
UploadServiceImpl.java
...y/admin/moudle/system/service/impl/UploadServiceImpl.java
+35
-1
application-dev.yml
src/main/resources/application-dev.yml
+2
-0
application.yml
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/com/lyy/admin/moudle/system/service/impl/UploadServiceImpl.java
View file @
fe3fbb34
package
com
.
lyy
.
admin
.
moudle
.
system
.
service
.
impl
;
package
com
.
lyy
.
admin
.
moudle
.
system
.
service
.
impl
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.TimeInterval
;
import
cn.hutool.core.img.Img
;
import
cn.hutool.core.img.Img
;
import
cn.hutool.core.img.ImgUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.IdUtil
;
import
com.lyy.admin.common.utils.hwobs.ObsUtils
;
import
com.lyy.admin.common.utils.hwobs.ObsUtils
;
...
@@ -18,6 +20,7 @@ import java.io.*;
...
@@ -18,6 +20,7 @@ import java.io.*;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.CompletableFuture
;
@Service
@Service
public
class
UploadServiceImpl
implements
UploadService
{
public
class
UploadServiceImpl
implements
UploadService
{
...
@@ -29,6 +32,8 @@ public class UploadServiceImpl implements UploadService {
...
@@ -29,6 +32,8 @@ public class UploadServiceImpl implements UploadService {
@Value
(
"${lyy.tempFilePath}"
)
@Value
(
"${lyy.tempFilePath}"
)
String
tempFilePath
;
String
tempFilePath
;
@Value
(
"${lyy.imgSize}"
)
Integer
imgSize
;
@Resource
@Resource
private
ObsUtils
obsUtils
;
private
ObsUtils
obsUtils
;
...
@@ -46,10 +51,17 @@ public class UploadServiceImpl implements UploadService {
...
@@ -46,10 +51,17 @@ public class UploadServiceImpl implements UploadService {
String
fileOriginalName
=
files
.
getOriginalFilename
();
String
fileOriginalName
=
files
.
getOriginalFilename
();
String
fileLastType
=
fileOriginalName
.
substring
(
files
.
getOriginalFilename
().
lastIndexOf
(
"."
));
String
fileLastType
=
fileOriginalName
.
substring
(
files
.
getOriginalFilename
().
lastIndexOf
(
"."
));
String
date
=
DateUtil
.
format
(
LocalDateTime
.
now
(),
"yyyy-MM-dd"
);
String
date
=
DateUtil
.
format
(
LocalDateTime
.
now
(),
"yyyy-MM-dd"
);
String
filePath
=
""
;
if
(
files
.
getSize
()/(
1024
*
1024
)
<=
imgSize
){
String
newFilename
=
IdUtil
.
simpleUUID
()
+
fileLastType
;
filePath
=
"/"
+
date
+
"/"
+
newFilename
;
InputStream
inputStream
=
files
.
getInputStream
();
obsUtils
.
ObsUpload
(
bucketName
,
rootPath
+
filePath
,
inputStream
);
inputStream
.
close
();
}
else
{
String
newFile
=
IdUtil
.
simpleUUID
();
String
newFile
=
IdUtil
.
simpleUUID
();
String
newFilename
=
newFile
+
fileLastType
;
String
newFilename
=
newFile
+
fileLastType
;
String
filePath
=
"/"
+
date
+
"/"
+
newFile
+
".jpg"
;
//将MultipartFile转为File,存储为本地临时文件
//将MultipartFile转为File,存储为本地临时文件
String
localDir
=
tempFilePath
+
newFilename
;
String
localDir
=
tempFilePath
+
newFilename
;
...
@@ -60,17 +72,39 @@ public class UploadServiceImpl implements UploadService {
...
@@ -60,17 +72,39 @@ public class UploadServiceImpl implements UploadService {
String
newFilename1
=
IdUtil
.
simpleUUID
()
+
".jpg"
;
String
newFilename1
=
IdUtil
.
simpleUUID
()
+
".jpg"
;
String
localDir1
=
tempFilePath
+
newFilename1
;
String
localDir1
=
tempFilePath
+
newFilename1
;
File
file1
=
FileUtil
.
file
(
localDir1
);
File
file1
=
FileUtil
.
file
(
localDir1
);
TimeInterval
timer
=
DateUtil
.
timer
();
Img
.
from
(
file
).
setQuality
(
1
).
write
(
file1
);
Img
.
from
(
file
).
setQuality
(
1
).
write
(
file1
);
System
.
out
.
println
(
timer
.
interval
());
InputStream
inputStream1
=
new
FileInputStream
(
localDir1
);
InputStream
inputStream1
=
new
FileInputStream
(
localDir1
);
filePath
=
"/"
+
date
+
"/"
+
newFile
+
".jpg"
;
obsUtils
.
ObsUpload
(
bucketName
,
rootPath
+
filePath
,
inputStream1
);
obsUtils
.
ObsUpload
(
bucketName
,
rootPath
+
filePath
,
inputStream1
);
//删除临时文件
//删除临时文件
CompletableFuture
.
runAsync
(()->
{
try
{
FileUtils
.
delete
(
file
);
FileUtils
.
delete
(
file
);
FileUtils
.
delete
(
file1
);
FileUtils
.
delete
(
file1
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
});
inputStream
.
close
();
inputStream1
.
close
();
}
return
rootPath
+
filePath
;
return
rootPath
+
filePath
;
}
}
public
static
void
main
(
String
[]
args
)
{
TimeInterval
timer
=
DateUtil
.
timer
();
ImgUtil
.
scale
(
FileUtil
.
file
(
"C:\\Users\\26996\\Pictures\\Screenshots\\1704418796(1).jpg"
),
FileUtil
.
file
(
"C:\\Users\\26996\\Pictures\\Screenshots\\170441879611111.jpg"
),
1
f
//缩放比例
);
System
.
out
.
println
(
timer
.
interval
());
}
@Override
@Override
public
String
uploadFile
(
MultipartFile
files
,
String
rootPath
)
throws
Exception
{
public
String
uploadFile
(
MultipartFile
files
,
String
rootPath
)
throws
Exception
{
//华为obs
//华为obs
...
...
src/main/resources/application-dev.yml
View file @
fe3fbb34
...
@@ -60,6 +60,8 @@ lyy:
...
@@ -60,6 +60,8 @@ lyy:
profile
:
/home/liyeyun/uploadPath
profile
:
/home/liyeyun/uploadPath
# 临时文件路径
# 临时文件路径
tempFilePath
:
/home/liyeyun/uploadPath/temp/
tempFilePath
:
/home/liyeyun/uploadPath/temp/
# 文件压缩阈值 (单位 M)
imgSize
:
1
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
# obsPath: http://img-t.knowingindustry.com
# obsPath: http://img-t.knowingindustry.com
obsPath
:
https://cfld-hw-obs-01.obs.cn-north-4.myhuaweicloud.com
obsPath
:
https://cfld-hw-obs-01.obs.cn-north-4.myhuaweicloud.com
...
...
src/main/resources/application.yml
View file @
fe3fbb34
...
@@ -110,7 +110,7 @@ anti:
...
@@ -110,7 +110,7 @@ anti:
#是否启用反爬虫插件
#是否启用反爬虫插件
enabled
:
false
enabled
:
false
#局部拦截时,需要反爬的接口列表,以','分隔,支持正则匹配。全局拦截模式下无需配置
#局部拦截时,需要反爬的接口列表,以','分隔,支持正则匹配。全局拦截模式下无需配置
include-urls
:
^${server.servlet.context-path}/.*$
include-urls
:
^${server.servlet.context-path}/.*$
,^/api/liyeren/.*$
#是否启用 IP Rule
#是否启用 IP Rule
ip-rule
:
ip-rule
:
enabled
:
true
enabled
:
true
...
...
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