Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mes
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
ximai
mes
Commits
db33419f
Commit
db33419f
authored
Aug 30, 2024
by
李驰骋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
通用上传调整
parent
efcc054c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
18 deletions
+23
-18
CommonController.java
...ava/com/ximai/web/controller/common/CommonController.java
+11
-17
pom.xml
common/pom.xml
+6
-0
UploadFileResult.java
.../com/ximai/common/core/domain/model/UploadFileResult.java
+6
-1
No files found.
admin/src/main/java/com/ximai/web/controller/common/CommonController.java
View file @
db33419f
...
...
@@ -94,7 +94,7 @@ public class CommonController {
String
url
=
ServerConfig
.
getUrl
()
+
fileName
;
UploadFileResult
rst
=
new
UploadFileResult
();
rst
.
setUrl
(
url
);
rst
.
setFile
Name
(
fileName
);
rst
.
setFile
Path
(
fileName
);
rst
.
setOriginalFilename
(
file
.
getOriginalFilename
());
rst
.
setSize
(
file
.
getSize
());
return
AjaxResult
.
success
(
rst
);
...
...
@@ -107,31 +107,25 @@ public class CommonController {
* 通用上传请求(多个)
*/
@PostMapping
(
"/uploads"
)
public
AjaxResult
2
uploadFiles
(
List
<
MultipartFile
>
files
)
throws
Exception
{
public
AjaxResult
<
List
<
UploadFileResult
>>
uploadFiles
(
@RequestParam
(
"file"
)
List
<
MultipartFile
>
files
)
throws
Exception
{
try
{
// 上传文件路径
String
filePath
=
RuoYiConfig
.
getUploadPath
();
List
<
String
>
urls
=
new
ArrayList
<
String
>();
List
<
String
>
fileNames
=
new
ArrayList
<
String
>();
List
<
String
>
newFileNames
=
new
ArrayList
<
String
>();
List
<
String
>
originalFilenames
=
new
ArrayList
<
String
>();
List
<
UploadFileResult
>
rst
=
new
ArrayList
<>();
for
(
MultipartFile
file
:
files
)
{
// 上传并返回新文件名称
String
fileName
=
FileUploadUtils
.
upload
(
filePath
,
file
);
String
url
=
ServerConfig
.
getUrl
()
+
fileName
;
urls
.
add
(
url
);
fileNames
.
add
(
fileName
);
newFileNames
.
add
(
FileUtils
.
getName
(
fileName
));
originalFilenames
.
add
(
file
.
getOriginalFilename
());
UploadFileResult
temp
=
new
UploadFileResult
();
temp
.
setUrl
(
url
);
temp
.
setFilePath
(
fileName
);
temp
.
setOriginalFilename
(
file
.
getOriginalFilename
());
temp
.
setSize
(
file
.
getSize
());
rst
.
add
(
temp
);
}
AjaxResult2
ajax
=
AjaxResult2
.
success
();
ajax
.
put
(
"urls"
,
StringUtils
.
join
(
urls
,
FILE_DELIMETER
));
ajax
.
put
(
"fileNames"
,
StringUtils
.
join
(
fileNames
,
FILE_DELIMETER
));
ajax
.
put
(
"newFileNames"
,
StringUtils
.
join
(
newFileNames
,
FILE_DELIMETER
));
ajax
.
put
(
"originalFilenames"
,
StringUtils
.
join
(
originalFilenames
,
FILE_DELIMETER
));
return
ajax
;
return
AjaxResult
.
success
(
rst
);
}
catch
(
Exception
e
)
{
return
AjaxResult
2
.
error
(
e
.
getMessage
());
return
AjaxResult
.
error
(
e
.
getMessage
());
}
}
...
...
common/pom.xml
View file @
db33419f
...
...
@@ -186,6 +186,12 @@
<version>
1.18.8
</version>
<!-- <optional>true</optional>-->
</dependency>
<dependency>
<groupId>
io.swagger
</groupId>
<artifactId>
swagger-annotations
</artifactId>
<version>
1.6.6
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
...
...
common/src/main/java/com/ximai/common/core/domain/model/UploadFileResult.java
View file @
db33419f
package
com
.
ximai
.
common
.
core
.
domain
.
model
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@Data
public
class
UploadFileResult
{
@ApiModelProperty
(
"URL"
)
String
url
;
String
fileName
;
@ApiModelProperty
(
"文件地址"
)
String
filePath
;
@ApiModelProperty
(
"原文件名"
)
String
originalFilename
;
@ApiModelProperty
(
"文件大小"
)
Long
size
;
}
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