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
da3faee0
Commit
da3faee0
authored
Jan 04, 2024
by
yaobaizheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件上传速度问题
parent
e6b2e0c9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
6 deletions
+25
-6
UploadServiceImpl.java
...y/admin/moudle/system/service/impl/UploadServiceImpl.java
+17
-6
application-dev.yml
src/main/resources/application-dev.yml
+2
-0
application-local.yml
src/main/resources/application-local.yml
+2
-0
application-prod.yml
src/main/resources/application-prod.yml
+2
-0
application-test.yml
src/main/resources/application-test.yml
+2
-0
No files found.
src/main/java/com/lyy/admin/moudle/system/service/impl/UploadServiceImpl.java
View file @
da3faee0
...
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
...
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
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
;
import
com.lyy.admin.moudle.system.service.UploadService
;
import
com.lyy.admin.moudle.system.service.UploadService
;
import
org.apache.commons.io.FileUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.util.FileCopyUtils
;
...
@@ -11,10 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -11,10 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.*
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -26,6 +24,9 @@ public class UploadServiceImpl implements UploadService {
...
@@ -26,6 +24,9 @@ public class UploadServiceImpl implements UploadService {
@Value
(
"${huaweiObs.bucketName}"
)
@Value
(
"${huaweiObs.bucketName}"
)
String
bucketName
;
String
bucketName
;
@Value
(
"${lyy.tempFilePath}"
)
String
tempFilePath
;
@Resource
@Resource
private
ObsUtils
obsUtils
;
private
ObsUtils
obsUtils
;
...
@@ -42,12 +43,22 @@ public class UploadServiceImpl implements UploadService {
...
@@ -42,12 +43,22 @@ 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 = LocalDateTimeUtils.formatNow("yyyy-MM-dd");
String
date
=
DateUtil
.
format
(
LocalDateTime
.
now
(),
"yyyy-MM-dd"
);
String
date
=
DateUtil
.
format
(
LocalDateTime
.
now
(),
"yyyy-MM-dd"
);
String
newFilename
=
IdUtil
.
simpleUUID
()
+
fileLastType
;
String
newFilename
=
IdUtil
.
simpleUUID
()
+
fileLastType
;
String
filePath
=
"/"
+
date
+
"/"
+
newFilename
;
String
filePath
=
"/"
+
date
+
"/"
+
newFilename
;
//将MultipartFile转为File,存储为本地临时文件
String
localDir
=
tempFilePath
+
newFilename
;
File
file
=
new
File
(
localDir
);
InputStream
inputStream
=
files
.
getInputStream
();
InputStream
inputStream
=
files
.
getInputStream
();
obsUtils
.
ObsUpload
(
bucketName
,
rootPath
+
filePath
,
inputStream
);
FileUtils
.
copyInputStreamToFile
(
inputStream
,
file
);
InputStream
inputStream1
=
new
FileInputStream
(
localDir
);
obsUtils
.
ObsUpload
(
bucketName
,
rootPath
+
filePath
,
inputStream1
);
//删除临时文件
FileUtils
.
delete
(
file
);
return
rootPath
+
filePath
;
return
rootPath
+
filePath
;
}
}
...
...
src/main/resources/application-dev.yml
View file @
da3faee0
...
@@ -58,6 +58,8 @@ spring:
...
@@ -58,6 +58,8 @@ spring:
lyy
:
lyy
:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile
:
/home/liyeyun/uploadPath
profile
:
/home/liyeyun/uploadPath
# 临时文件路径
tempFilePath
:
/home/liyeyun/uploadPath/temp/
# 华为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-local.yml
View file @
da3faee0
...
@@ -58,6 +58,8 @@ spring:
...
@@ -58,6 +58,8 @@ spring:
lyy
:
lyy
:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile
:
D:/uploadPath
profile
:
D:/uploadPath
# 临时文件路径
tempFilePath
:
D:/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
obsPath
:
http://img-t.knowingindustry.com
obsPath
:
http://img-t.knowingindustry.com
#密码盐
#密码盐
...
...
src/main/resources/application-prod.yml
View file @
da3faee0
...
@@ -58,6 +58,8 @@ spring:
...
@@ -58,6 +58,8 @@ spring:
lyy
:
lyy
:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile
:
/home/liyeyun/uploadPath
profile
:
/home/liyeyun/uploadPath
# 临时文件路径
tempFilePath
:
/home/liyeyun/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
# 华为OBS文件路径 示例( https://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-test.yml
View file @
da3faee0
...
@@ -58,6 +58,8 @@ spring:
...
@@ -58,6 +58,8 @@ spring:
lyy
:
lyy
:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile
:
/home/liyeyun/uploadPath
profile
:
/home/liyeyun/uploadPath
# 临时文件路径
tempFilePath
:
/home/liyeyun/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
# 华为OBS文件路径 示例( https://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
#密码盐
#密码盐
...
...
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