Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
TDLCloud
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
WitCloud
TDLCloud
Commits
16f97eb9
Commit
16f97eb9
authored
May 25, 2018
by
zhuangzhuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
5.25--图片上传
parent
34c42b90
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
12 deletions
+93
-12
OSSClientConstants.java
src/main/java/com/example/tdl/util/OSSClientConstants.java
+1
-1
PicUploadController.java
src/main/java/com/example/tdl/web/PicUploadController.java
+92
-0
WarehouseController.java
src/main/java/com/example/tdl/web/WarehouseController.java
+0
-11
No files found.
src/main/java/com/example/tdl/util/OSSClientConstants.java
View file @
16f97eb9
...
@@ -14,7 +14,7 @@ public class OSSClientConstants {
...
@@ -14,7 +14,7 @@ public class OSSClientConstants {
public
static
final
String
ACCESS_KEY_SECRET
=
"JgupdkkFg1Ot1eRsdk6wXU3CJiWdaw"
;
public
static
final
String
ACCESS_KEY_SECRET
=
"JgupdkkFg1Ot1eRsdk6wXU3CJiWdaw"
;
//阿里云API的bucket名称
//阿里云API的bucket名称
public
static
final
String
BACKET_NAME
=
"
witcloud-oss
"
;
//uploadexcelhltp
public
static
final
String
BACKET_NAME
=
"
tdlcloud
"
;
//uploadexcelhltp
//阿里云API的文件夹名称
//阿里云API的文件夹名称
...
...
src/main/java/com/example/tdl/web/PicUploadController.java
0 → 100644
View file @
16f97eb9
package
com
.
example
.
tdl
.
web
;
import
com.aliyun.oss.OSSClient
;
import
com.example.tdl.domain.dto.CommFeedback
;
import
com.example.tdl.util.AliyunOSSClientUtil
;
import
com.google.gson.Gson
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.shiro.SecurityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
@RestController
(
"/picUpload"
)
public
class
PicUploadController
{
private
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
PicUploadController
.
class
);
Gson
gson
=
new
Gson
();
CommFeedback
fb
=
new
CommFeedback
();
// 允许上传的格式
private
static
final
String
[]
IMAGE_TYPE
=
new
String
[]{
".jpg"
,
".png"
};
//上传图片
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"header"
,
name
=
"Account_token"
,
value
=
"token"
,
required
=
true
,
dataType
=
"String"
),
})
@RequestMapping
(
value
=
"/upload"
,
method
=
RequestMethod
.
POST
)
public
String
upload
(
MultipartFile
multipartFile
,
@RequestParam
(
value
=
"imageType"
,
required
=
true
)
String
imageType
)
{
if
(
multipartFile
.
isEmpty
()
||
StringUtils
.
isBlank
(
multipartFile
.
getOriginalFilename
()))
{
fb
.
setCode
(
0
);
fb
.
setMessage
(
"图片不能为空"
);
return
gson
.
toJson
(
fb
);
}
if
(
multipartFile
.
getSize
()
>
5
*
1024
*
1024
)
{
fb
.
setCode
(
0
);
fb
.
setMessage
(
"上传图片大小不能超过5M!"
);
return
gson
.
toJson
(
fb
);
}
// 校验图片格式
boolean
isLegal
=
false
;
// 判断文件后缀名是否符合
for
(
String
type
:
IMAGE_TYPE
)
{
if
(
StringUtils
.
endsWithIgnoreCase
(
multipartFile
.
getOriginalFilename
(),
type
))
{
isLegal
=
true
;
break
;
}
}
if
(
isLegal
)
{
try
{
//初始化OSSClient
OSSClient
ossClient
=
AliyunOSSClientUtil
.
getOSSClient
();
LOGGER
.
info
(
multipartFile
.
getOriginalFilename
());
String
url
=
AliyunOSSClientUtil
.
uploadImg2Oss
(
ossClient
,
multipartFile
,
System
.
currentTimeMillis
()+
"TM"
,
imageType
);
if
(
url
==
null
)
{
fb
.
setMessage
(
"上传失败"
);
fb
.
setCode
(
0
);
}
else
{
if
(
"user"
.
equals
(
imageType
)){
//https://tdlcloud.oss-cn-shanghai.aliyuncs.com
fb
.
setMessage
(
"https://tdlcloud.oss-cn-shanghai.aliyuncs.com/pic/userImage/"
+
url
);
}
else
if
(
"company"
.
equals
(
imageType
)){
fb
.
setMessage
(
"https://tdlcloud.oss-cn-shanghai.aliyuncs.com/pic/companyLog/"
+
url
);
}
else
if
(
"palte"
.
equals
(
imageType
)){
fb
.
setMessage
(
"https://tdlcloud.oss-cn-shanghai.aliyuncs.com/pic/palteImage/"
+
url
);
}
else
if
(
"wareHouse"
.
equals
(
imageType
)){
fb
.
setMessage
(
"https://tdlcloud.oss-cn-shanghai.aliyuncs.com/pic/wareHouseImage/"
+
url
);
}
else
if
(
"circuit"
.
equals
(
imageType
)){
fb
.
setMessage
(
"https://tdlcloud.oss-cn-shanghai.aliyuncs.com/pic/userImage/"
+
url
);
}
fb
.
setCode
(
1
);
}
}
catch
(
Exception
e
)
{
fb
.
setCode
(
0
);
fb
.
setMessage
(
"上传失败"
);
e
.
printStackTrace
();
LOGGER
.
info
(
e
.
toString
());
}
}
else
{
fb
.
setCode
(
0
);
fb
.
setMessage
(
"上传图片格式不正确"
);
}
return
gson
.
toJson
(
fb
);
}
}
src/main/java/com/example/tdl/web/WarehouseController.java
View file @
16f97eb9
...
@@ -252,17 +252,6 @@ public class WarehouseController {
...
@@ -252,17 +252,6 @@ public class WarehouseController {
String
datum
=
tokenRedisService
.
get
(
"TOKEN_"
+
token
);
String
datum
=
tokenRedisService
.
get
(
"TOKEN_"
+
token
);
UserRedisVo
user
=
gson
.
fromJson
(
datum
,
UserRedisVo
.
class
);
UserRedisVo
user
=
gson
.
fromJson
(
datum
,
UserRedisVo
.
class
);
String
warehouseNo
=
getWarehouseNo
();
String
warehouseNo
=
getWarehouseNo
();
// if (multipartFile.isEmpty() || StringUtils.isBlank(multipartFile.getOriginalFilename())) {
// fb.setCode(0);
// fb.setMessage("图片不能为空");
// return gson.toJson(fb);
// }
// if (multipartFile.getSize() > 5 * 1024 * 1024) {
// fb.setCode(0);
// fb.setMessage("上传图片大小不能超过5M!");
// return gson.toJson(fb);
// }
// String img = PicUploadUtil.uploadImage(multipartFile,warehouseNo,"warehouse");
if
(
StringUtils
.
isEmpty
(
addWarehouseVo
.
getWarehouseName
())){
if
(
StringUtils
.
isEmpty
(
addWarehouseVo
.
getWarehouseName
())){
fb
.
setCode
(
0
);
fb
.
setCode
(
0
);
fb
.
setMessage
(
"仓库名不能为空"
);
fb
.
setMessage
(
"仓库名不能为空"
);
...
...
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