Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bailuntec-cost
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
huluobin
bailuntec-cost
Commits
4de57bf2
Commit
4de57bf2
authored
Jun 23, 2021
by
yangjinhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UiBot上传七牛云接口
parent
07e548c6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
127 additions
and
1 deletion
+127
-1
pom.xml
cost-service/pom.xml
+13
-1
FileController.java
...m/blt/other/module/commons/controller/FileController.java
+13
-0
QNUtils.java
...rc/main/java/com/blt/other/module/cost/utils/QNUtils.java
+101
-0
No files found.
cost-service/pom.xml
View file @
4de57bf2
...
@@ -69,6 +69,13 @@
...
@@ -69,6 +69,13 @@
<version>
3.17
</version>
<version>
3.17
</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
2.8.5
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml-schemas
</artifactId>
<artifactId>
poi-ooxml-schemas
</artifactId>
...
@@ -86,7 +93,12 @@
...
@@ -86,7 +93,12 @@
<groupId>
io.springfox
</groupId>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<artifactId>
springfox-swagger2
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.7.0
</version>
</dependency>
<dependency>
<dependency>
<groupId>
io.swagger
</groupId>
<groupId>
io.swagger
</groupId>
...
...
cost-service/src/main/java/com/blt/other/module/commons/controller/FileController.java
View file @
4de57bf2
...
@@ -5,6 +5,7 @@ import com.blt.other.common.annotation.LoginIgnore;
...
@@ -5,6 +5,7 @@ import com.blt.other.common.annotation.LoginIgnore;
import
com.blt.other.common.exception.BizRuntimeException
;
import
com.blt.other.common.exception.BizRuntimeException
;
import
com.blt.other.common.util.PathUtil
;
import
com.blt.other.common.util.PathUtil
;
import
com.blt.other.module.cost.utils.CostFileUtil
;
import
com.blt.other.module.cost.utils.CostFileUtil
;
import
com.blt.other.module.cost.utils.QNUtils
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
@@ -37,4 +38,16 @@ public class FileController {
...
@@ -37,4 +38,16 @@ public class FileController {
}
}
throw
new
BizRuntimeException
(
"文件不能为空"
);
throw
new
BizRuntimeException
(
"文件不能为空"
);
}
}
@LoginIgnore
@ApiOperation
(
"七牛云UiBot上传文件接口"
)
@PostMapping
(
"uiBot/uploadXlsx"
)
public
CostResult
<
String
>
xUpload
(
MultipartFile
file
)
{
if
(
file
!=
null
)
{
String
url
=
QNUtils
.
upLoad
(
file
);
return
CostResult
.
success
(
url
);
}
throw
new
BizRuntimeException
(
"文件不能为空"
);
}
}
}
cost-service/src/main/java/com/blt/other/module/cost/utils/QNUtils.java
0 → 100644
View file @
4de57bf2
package
com
.
blt
.
other
.
module
.
cost
.
utils
;
import
com.google.gson.Gson
;
import
com.qiniu.common.QiniuException
;
import
com.qiniu.http.Response
;
import
com.qiniu.storage.Configuration
;
import
com.qiniu.storage.Region
;
import
com.qiniu.storage.UploadManager
;
import
com.qiniu.storage.model.DefaultPutRet
;
import
com.qiniu.util.Auth
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.io.InputStream
;
public
class
QNUtils
{
/**
* Key
*/
private
static
final
String
ACCESS_KEY
=
"QSvtvN4Ons1CiNzaMGqx8XmDaiM1L0ZqSwJ2YoTn"
;
/**
* 秘钥
*/
private
static
final
String
SECRET_KEY
=
"yagRd-cBOVhkRGGT-o_reMqNVjI8_k7YwoTXkhrm"
;
/**
* 存储桶
*/
private
static
final
String
BUCKET
=
"uibot"
;
private
static
final
String
BASE_URL
=
"qv3ist3f9.hn-bkt.clouddn.com"
;
/**
* 上传管理
*/
private
static
UploadManager
uploadManager
;
private
QNUtils
()
{
//构造一个带指定 Region 对象的配置类
Configuration
config
=
new
Configuration
(
Region
.
region2
());
uploadManager
=
new
UploadManager
(
config
);
}
private
static
UploadManager
getInstance
()
{
if
(
uploadManager
==
null
)
{
new
QNUtils
();
}
return
uploadManager
;
}
/**
* 生成上传凭证Token
*
* @return
*/
public
static
String
getToken
()
{
Auth
auth
=
Auth
.
create
(
ACCESS_KEY
,
SECRET_KEY
);
String
upToken
=
auth
.
uploadToken
(
BUCKET
);
System
.
out
.
println
(
upToken
);
return
upToken
;
}
public
static
String
upLoad
(
MultipartFile
file
)
{
// 默认不指定key的情况下,以文件内容的hash值作为文件名
String
key
=
file
.
getOriginalFilename
();
String
url
=
""
;
try
{
InputStream
inputStream
=
file
.
getInputStream
();
// byte[] byteData = IOUtils.toByteArray(inputStream);//把流转字节数组
Response
response
=
getInstance
().
put
(
inputStream
,
key
,
getToken
(),
null
,
null
);
// Response response = getInstance().put(byteData, key, getToken());
//解析上传成功的结果
try
{
DefaultPutRet
putRet
=
new
Gson
().
fromJson
(
response
.
bodyString
(),
DefaultPutRet
.
class
);
System
.
out
.
println
(
putRet
.
key
);
System
.
out
.
println
(
putRet
.
hash
);
url
=
BASE_URL
+
putRet
.
key
;
}
catch
(
QiniuException
e
)
{
Response
r
=
e
.
response
;
System
.
err
.
println
(
r
.
toString
());
try
{
System
.
err
.
println
(
r
.
bodyString
());
}
catch
(
QiniuException
ex2
)
{
//ignore
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
url
;
}
}
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