Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoban3.0
haoban-manage3.0
Commits
4be19ace
Commit
4be19ace
authored
Sep 01, 2022
by
墨竹
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:上传文件名字修改
parent
e1878dfb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
20 deletions
+18
-20
UploadController.java
...om/gic/haoban/manage/web/controller/UploadController.java
+18
-20
No files found.
haoban-manage3-web/src/main/java/com/gic/haoban/manage/web/controller/UploadController.java
View file @
4be19ace
...
@@ -23,19 +23,20 @@ import java.util.HashSet;
...
@@ -23,19 +23,20 @@ import java.util.HashSet;
import
java.util.Set
;
import
java.util.Set
;
@RestController
@RestController
public
class
UploadController
extends
WebBaseController
{
public
class
UploadController
extends
WebBaseController
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
UploadController
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
UploadController
.
class
);
private
static
Set
<
String
>
FILE_TYPE
=
new
HashSet
<>(
);
private
static
Set
<
String
>
FILE_TYPE
=
new
HashSet
<>();
static
{
static
{
for
(
BucketNameEnum
value:
BucketNameEnum
.
values
())
{
for
(
BucketNameEnum
value
:
BucketNameEnum
.
values
())
{
FILE_TYPE
.
add
(
value
.
getName
()
);
FILE_TYPE
.
add
(
value
.
getName
()
);
}
}
}
}
@RequestMapping
(
"/upload-file"
)
@RequestMapping
(
"/upload-file"
)
@ResponseBody
@ResponseBody
public
HaobanResponse
upload
(
@RequestParam
MultipartFile
file
,
@RequestParam
String
fileType
)
throws
Exception
{
public
HaobanResponse
upload
(
@RequestParam
MultipartFile
file
,
@RequestParam
String
fileType
)
throws
Exception
{
if
(
file
==
null
||
file
.
isEmpty
())
{
if
(
file
==
null
||
file
.
isEmpty
())
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
}
String
name
=
file
.
getOriginalFilename
();
String
name
=
file
.
getOriginalFilename
();
...
@@ -47,24 +48,22 @@ public class UploadController extends WebBaseController{
...
@@ -47,24 +48,22 @@ public class UploadController extends WebBaseController{
}
}
String
suffix
=
name
.
substring
(
name
.
lastIndexOf
(
"."
)
+
1
);
String
suffix
=
name
.
substring
(
name
.
lastIndexOf
(
"."
)
+
1
);
name
=
SecureUtil
.
md5
(
name
)
+
"."
+
suffix
;
name
=
SecureUtil
.
md5
(
name
)
+
"."
+
suffix
;
String
location
=
System
.
getProperty
(
"user.dir"
)+
"/data/tmp/"
;
String
location
=
System
.
getProperty
(
"user.dir"
)
+
"/data/tmp/"
;
//b
//b
long
len
=
file
.
getSize
();
long
len
=
file
.
getSize
();
File
templateFile
=
new
File
(
location
+
name
);
File
templateFile
=
new
File
(
location
+
name
);
FileUtils
.
copyInputStreamToFile
(
file
.
getInputStream
(),
templateFile
);
FileUtils
.
copyInputStreamToFile
(
file
.
getInputStream
(),
templateFile
);
// 2.上传腾讯云
// 2.上传腾讯云
String
dayFilePath
=
LocalDateTime
.
now
().
format
(
DateTimeFormatter
.
ofPattern
(
DateUtil
.
FORMAT_DATETIME_14
)
);
String
dayFilePath
=
LocalDateTime
.
now
().
format
(
DateTimeFormatter
.
ofPattern
(
DateUtil
.
FORMAT_DATETIME_14
)
);
String
key
=
"haoban/"
+
dayFilePath
+
"/"
+
n
ame
;
String
key
=
"haoban/"
+
dayFilePath
+
"/"
+
mediaN
ame
;
fileType
=
FILE_TYPE
.
contains
(
fileType
)?
fileType:
BucketNameEnum
.
OTHER_90000
.
getName
();
fileType
=
FILE_TYPE
.
contains
(
fileType
)
?
fileType
:
BucketNameEnum
.
OTHER_90000
.
getName
();
try
{
try
{
String
url
=
FileUploadUtil
.
simpleUploadFileFromLocal
(
templateFile
,
key
,
fileType
);
String
url
=
FileUploadUtil
.
simpleUploadFileFromLocal
(
templateFile
,
key
,
fileType
);
if
(
templateFile
!=
null
)
{
if
(
templateFile
!=
null
)
{
templateFile
.
delete
();
templateFile
.
delete
();
}
}
JSONObject
res
=
new
JSONObject
();
JSONObject
res
=
new
JSONObject
();
res
.
put
(
"name"
,
name
);
res
.
put
(
"name"
,
name
);
res
.
put
(
"mediaName"
,
mediaName
);
res
.
put
(
"mediaName"
,
mediaName
);
...
@@ -73,9 +72,8 @@ public class UploadController extends WebBaseController{
...
@@ -73,9 +72,8 @@ public class UploadController extends WebBaseController{
res
.
put
(
"key"
,
key
);
res
.
put
(
"key"
,
key
);
res
.
put
(
"url"
,
"https://"
+
url
);
res
.
put
(
"url"
,
"https://"
+
url
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
res
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
res
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
info
(
"异常:{}"
,
e
.
getMessage
(),
e
);
logger
.
info
(
"异常:{}"
,
e
);
return
resultResponse
(
HaoBanErrCode
.
ERR_0
);
return
resultResponse
(
HaoBanErrCode
.
ERR_0
);
}
}
}
}
...
...
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