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
df105773
Commit
df105773
authored
Apr 21, 2021
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新了上传文件的出现的问题
parent
e5fd486e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
42 deletions
+48
-42
pom.xml
+4
-0
src/main/java/cn/timer/api/controller/oss/OSSController.java
+14
-41
src/main/java/cn/timer/api/service/OSSService.java
+26
-0
src/main/java/cn/timer/api/service/impl/OSSServiceImpl.java
+3
-0
src/main/java/cn/timer/api/utils/aliyun/AliyunSMS.java
+1
-1
No files found.
pom.xml
View file @
df105773
...
...
@@ -421,6 +421,10 @@
<artifactId>
htmlunit
</artifactId>
<version>
2.43.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
</dependency>
</dependencies>
<repositories>
...
...
src/main/java/cn/timer/api/controller/oss/OSSController.java
View file @
df105773
...
...
@@ -3,17 +3,12 @@ package cn.timer.api.controller.oss;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
import
cn.timer.api.service.OSSService
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
cn.timer.api.config.annotation.CurrentUser
;
...
...
@@ -32,6 +27,8 @@ import io.swagger.annotations.ApiOperation;
public
class
OSSController
{
@Autowired
private
OSSUtil
oss
;
@Autowired
private
OSSService
ossService
;
/**
* 上传普通文件
...
...
@@ -41,21 +38,11 @@ public class OSSController {
*/
@PostMapping
(
value
=
"/upload"
)
@ApiOperation
(
value
=
"上传普通文件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
String
>
upload
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
false
)
String
moudle
,
@Param
(
"file"
)
MultipartFile
file
)
{
String
url
=
null
;
int
uuid
=
(
int
)
(
Math
.
random
()*
100
+
1
);
String
path
=
"8timer2.0/"
+
userBean
.
getOrgCode
()
+
"/"
+
moudle
+
"/"
+
uuid
+
"-"
+
file
.
getOriginalFilename
();
if
(
file
==
null
||
file
.
getSize
()
<=
0
)
{
return
ResultUtil
.
error
(
"上传的文件为空,请重新选择!"
);
}
else
{
try
{
url
=
oss
.
uploadFile
(
path
,
file
.
getInputStream
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
ResultUtil
.
data
(
url
,
"上传成功!"
);
}
@ResponseBody
public
Result
<
String
>
upload
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
false
)
String
moudle
,
@RequestParam
(
"filename"
)
MultipartFile
file
)
throws
Exception
{
Result
<
String
>
data
=
ossService
.
upload
(
userBean
.
getOrgCode
(),
moudle
,
file
);
return
data
;
}
/**
...
...
@@ -68,23 +55,10 @@ public class OSSController {
@ApiOperation
(
value
=
"批量上传普通文件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
uploads
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
false
)
String
moudle
,
@Param
(
"files"
)
List
<
MultipartFile
>
files
)
{
String
url
=
null
;
List
<
String
>
list
=
new
ArrayList
<
String
>();
for
(
MultipartFile
file
:
files
)
{
int
uuid
=
(
int
)
(
Math
.
random
()*
100
+
1
);
String
path
=
"8timer2.0/"
+
userBean
.
getOrgCode
()
+
"/"
+
moudle
+
"/"
+
uuid
+
"-"
+
file
.
getOriginalFilename
();
if
(
file
==
null
||
file
.
getSize
()
<=
0
)
{
return
ResultUtil
.
error
(
"上传的文件为空,请重新选择!"
);
}
else
{
try
{
url
=
oss
.
uploadFile
(
path
,
file
.
getInputStream
());
list
.
add
(
url
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
ResultUtil
.
data
(
list
,
"上传成功!"
);
Result
<
Object
>
data
=
ossService
.
uploads
(
userBean
.
getOrgCode
(),
moudle
,
files
);
return
data
;
}
/**
...
...
@@ -94,8 +68,7 @@ public class OSSController {
@ApiOperation
(
value
=
"上传私密文件"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
String
>
uploadPrivate
(
@CurrentUser
UserBean
userBean
,
@RequestParam
(
required
=
false
)
String
moudle
,
@Param
(
"file"
)
MultipartFile
file
)
{
int
uuid
=
(
int
)
(
Math
.
random
()*
100
+
1
);
String
path
=
"8timer2.0/"
+
userBean
.
getOrgCode
()
+
"/"
+
moudle
+
"/"
+
uuid
+
"-"
+
file
.
getOriginalFilename
();
String
path
=
"8timer2.0/"
+
userBean
.
getOrgCode
()
+
"/"
+
moudle
+
"/"
+
file
.
getOriginalFilename
();
if
(
file
==
null
||
file
.
getSize
()
<=
0
)
{
return
ResultUtil
.
error
(
"上传的文件为空,请重新选择!"
);
}
else
{
...
...
src/main/java/cn/timer/api/service/OSSService.java
View file @
df105773
...
...
@@ -11,6 +11,8 @@ import org.springframework.web.multipart.MultipartFile;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 上传文件的实现层
...
...
@@ -54,4 +56,28 @@ public class OSSService implements OSSServiceImpl {
File
filePath
=
new
File
(
path
);
return
filePath
;
}
public
Result
<
Object
>
uploads
(
int
orgCode
,
String
moudle
,
List
<
MultipartFile
>
files
){
String
url
=
null
;
List
<
String
>
list
=
new
ArrayList
<
String
>();
for
(
MultipartFile
file
:
files
)
{
String
randomNickname
=
RandomNum
.
getRandomNickname
();
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
{
url
=
oss
.
uploadFile
(
filePath
,
file
.
getInputStream
());
list
.
add
(
url
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
ResultUtil
.
data
(
list
,
"上传成功!"
);
}
}
src/main/java/cn/timer/api/service/impl/OSSServiceImpl.java
View file @
df105773
...
...
@@ -3,7 +3,10 @@ package cn.timer.api.service.impl;
import
cn.timer.api.utils.Result
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
public
interface
OSSServiceImpl
{
public
Result
<
String
>
upload
(
int
orgCode
,
String
moudle
,
MultipartFile
file
);
public
Result
<
Object
>
uploads
(
int
orgCode
,
String
moudle
,
List
<
MultipartFile
>
files
);
}
src/main/java/cn/timer/api/utils/aliyun/AliyunSMS.java
View file @
df105773
...
...
@@ -61,7 +61,7 @@ public class AliyunSMS {
/**
*
* @param
phon
e
* @param
cod
e
* @param templateCode 1."身份验证验证码" 2."登录确认验证码" 3."登录异常验证码" 4."用户注册验证码"
* 5."修改密码验证码" 6."信息变更验证码"
*/
...
...
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