Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rs-cloud-platform
Project
Project
Details
Activity
Releases
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
周健威
rs-cloud-platform
Commits
1a31f907
Commit
1a31f907
authored
Jan 12, 2021
by
周健威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改代码
parent
65909eff
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
17 deletions
+63
-17
bootstrap.yml
...ter/rs-datacenter-server/src/main/resources/bootstrap.yml
+4
-0
UploadController.java
...ns/platform/rs/universal/controller/UploadController.java
+18
-17
UploadService.java
...m/upyuns/platform/rs/universal/service/UploadService.java
+41
-0
No files found.
rs-datacenter/rs-datacenter-server/src/main/resources/bootstrap.yml
View file @
1a31f907
...
...
@@ -9,6 +9,10 @@
# profiles:
# active: dev
spring
:
# servlet:
# multipart:
# max-file-size: 3000MB
# max-request-size: 3000MB
profiles
:
active
:
dev
application
:
...
...
rs-universal/rs-universal-server/src/main/java/com/upyuns/platform/rs/universal/controller/UploadController.java
View file @
1a31f907
package
com
.
upyuns
.
platform
.
rs
.
universal
.
controller
;
import
cn.hutool.core.img.ImgUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
...
...
@@ -45,21 +46,21 @@ public class UploadController{
@Autowired
UploadZipService
uploadZipService
;
private
static
Integer
MAX_DRIVING_LICENSE_SIZE
=
10
*
1024
*
1024
;
//10M
@RequestMapping
(
value
=
"/app/unauth/upload"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
upload
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
value
=
"prefix"
,
defaultValue
=
"app"
)
String
prefix
)
throws
Exception
{
String
contentType
=
file
.
getContentType
();
//图片文件类型
// String fileName = file.getOriginalFilename(); //图片名字
/* if (!contentType.equals("image/jpeg") && !contentType.equals("image/gif")&&!contentType.equals("image/png")) {
return JsonResultUtil.createFailedResult(2001,"格式不对!!!");
}*/
if
(
file
.
getSize
()
>
MAX_DRIVING_LICENSE_SIZE
)
{
return
JsonResultUtil
.
createFailedResult
(
2002
,
"大小超过限制!!!"
);
return
JsonResultUtil
.
createSuccessResultWithObj
(
uploadService
.
uploadFile
(
file
,
prefix
));
}
@RequestMapping
(
value
=
"/app/unauth/uploadDispose"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
uploadDispose
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
value
=
"prefix"
,
defaultValue
=
"app"
)
String
prefix
)
throws
Exception
{
String
contentType
=
file
.
getContentType
();
//图片文件类型
return
JsonResultUtil
.
createSuccessResultWithObj
(
uploadService
.
uploadFile
(
file
,
prefix
));
}
...
...
@@ -82,9 +83,9 @@ public class UploadController{
/* if (!contentType.equals("image/jpeg") && !contentType.equals("image/gif")&&!contentType.equals("image/png")) {
return JsonResultUtil.createFailedResult(2001,"格式不对!!!");
}*/
if
(
file
.
getSize
()
>
MAX_DRIVING_LICENSE_SIZE
)
{
return
JsonResultUtil
.
createFailedResult
(
2002
,
"大小超过限制!!!"
);
}
//
if (file.getSize() > MAX_DRIVING_LICENSE_SIZE) {
//
return JsonResultUtil.createFailedResult(2002,"大小超过限制!!!");
//
}
return
JsonResultUtil
.
createSuccessResultWithObj
(
uploadService
.
uploadFile
(
file
,
prefix
));
}
...
...
@@ -106,10 +107,10 @@ public class UploadController{
MultipartFile
file
=
files
[
i
];
//保存文件
String
contentType
=
file
.
getContentType
();
if
(
file
.
getSize
()
>
MAX_DRIVING_LICENSE_SIZE
)
{
log
.
error
(
"大小超过限制!!!"
);
continue
;
}
//
if (file.getSize() > MAX_DRIVING_LICENSE_SIZE) {
//
log.error("大小超过限制!!!");
//
continue;
//
}
String
path
=
uploadService
.
uploadFile
(
file
,
prefix
);
if
(
StringUtils
.
isBlank
(
urls
)){
urls
+=
path
;
...
...
rs-universal/rs-universal-server/src/main/java/com/upyuns/platform/rs/universal/service/UploadService.java
View file @
1a31f907
package
com
.
upyuns
.
platform
.
rs
.
universal
.
service
;
import
cn.hutool.core.img.ImgUtil
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.util.process.SystemConfig
;
import
com.upyuns.platform.rs.universal.constant.RedisKey
;
...
...
@@ -19,7 +20,12 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.imageio.stream.ImageInputStream
;
import
javax.imageio.stream.ImageOutputStream
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.util.UUID
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -61,6 +67,41 @@ public class UploadService {
return
realFileRelPath
;
}
/**
* 写入上传文件,返回相对路径
* @param file
* @return
*/
public
String
uploadFileDispose
(
MultipartFile
file
,
String
prefix
)
throws
Exception
{
//创建本日存放目录
DateTime
now
=
DateTime
.
now
();
String
dirPathToday
=
"/"
+
prefix
+
"/"
+
now
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
String
redisNoKey
=
RedisKey
.
UPLOAD_FILE_NO_PREFIX
+
now
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
Long
no
=
redisTemplate
.
opsForValue
().
increment
(
redisNoKey
);
if
(
no
.
equals
(
1
l
)){
redisTemplate
.
expire
(
redisNoKey
,
1
,
TimeUnit
.
DAYS
);
}
String
fileName
=
file
.
getOriginalFilename
();
String
realFileRelPath
=
dirPathToday
+
"/"
+
no
+
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
//文件存放路径
String
filePath
=
baseUploadPath
+
realFileRelPath
;
//缩略
BufferedImage
bufferedImage
=
ImgUtil
.
read
(
file
.
getInputStream
());
Float
scale
=
800
f
/
bufferedImage
.
getHeight
();
Image
newImage
=
ImgUtil
.
scale
(
bufferedImage
,
scale
);
//加水印
Image
newImage2
=
ImgUtil
.
pressText
(
newImage
,
"人民星云"
,
Color
.
WHITE
,
null
,
0
,
0
,
0.2f
);
//将文件写入指定位置
ImgUtil
.
write
(
newImage2
,
new
File
(
filePath
));
//将文件写入指定位置
//FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
realFileRelPath
=
xx_url
+
SystemConfig
.
XXMP_URL
+
realFileRelPath
;
return
realFileRelPath
;
}
/**
* 写入上传文件,返回相对路径
* @param imgFile
...
...
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