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
3c027a0f
Commit
3c027a0f
authored
Jun 16, 2020
by
dengshichuan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dsc' into 'develop'
Dsc See merge request 8timerv2/8timerapiv200!200
parents
2e54e3d9
9038bf90
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
16 deletions
+18
-16
src/main/java/cn/timer/api/controller/oss/OSSController.java
+14
-15
src/main/java/cn/timer/api/utils/aliyun/OSSUtil.java
+4
-1
No files found.
src/main/java/cn/timer/api/controller/oss/OSSController.java
View file @
3c027a0f
...
...
@@ -8,7 +8,6 @@ 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.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -105,20 +104,20 @@ public class OSSController {
}
}
/**
* 下载
*/
@GetMapping
(
value
=
"/download"
)
@ApiOperation
(
value
=
"通过url直接下载文件
"
,
httpMethod
=
"GET"
,
notes
=
"接口发布说明"
)
public
Result
<
String
>
download
(
@CurrentUser
UserBean
userBean
,
@RequestParam
String
url
,
@RequestParam
String
savePath
)
{
try
{
oss
.
download
(
url
,
savePath
);
}
catch
(
Exception
e
)
{
return
ResultUtil
.
error
(
"下载失败"
);
}
return
ResultUtil
.
data
(
"下载成功"
);
}
//
/**
//
* 下载
//
*/
//
@GetMapping(value = "/download")
// @ApiOperation(value = "通过url下载文件到服务器
", httpMethod = "GET", notes = "接口发布说明")
//
public Result<String> download(@CurrentUser UserBean userBean, @RequestParam String url,
//
@RequestParam String savePath) {
//
try {
//
oss.download(url, savePath);
//
} catch (Exception e) {
//
return ResultUtil.error("下载失败");
//
}
//
return ResultUtil.data("下载成功");
//
}
/**
* 获取私密文件url(设置为10分钟有效)
...
...
src/main/java/cn/timer/api/utils/aliyun/OSSUtil.java
View file @
3c027a0f
...
...
@@ -29,6 +29,7 @@ import com.aliyun.oss.model.ListObjectsRequest;
import
com.aliyun.oss.model.OSSObject
;
import
com.aliyun.oss.model.OSSObjectSummary
;
import
com.aliyun.oss.model.ObjectListing
;
import
com.aliyun.oss.model.ObjectMetadata
;
import
com.aliyun.oss.model.PutObjectRequest
;
import
cn.hutool.core.date.DateField
;
...
...
@@ -496,11 +497,13 @@ public class OSSUtil {
// String accessKeySecret = "EJ6qToT4T4u0B5Rb6qrta9WkyGHvGR";
// String bucketName = "8time-v2";
// String objectName = "8timer2.0/117/test/测试.pdf";
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
endpoint
,
accessKeyId
,
accessKeySecret
);
// String url = "http://8time-v2.oss-cn-shenzhen.aliyuncs.com/8timer2.0/310/qyxx/filepath/158872957193802f4a85a-9dd9-483a-9049-86fac5c73bd5.pdf?Expires=4747952308&OSSAccessKeyId=LTAI4FuaShJWQ1dggsFWG5CC&Signature=z%2FNIX0RrxnLuBLAS9olPpxxsCrI%3D";
try
{
// 带进度条的下载。
ossClient
.
getObject
(
new
GetObjectRequest
(
new
URL
(
url
),
null
),
new
File
(
savePath
));
ObjectMetadata
a
=
ossClient
.
getObject
(
new
GetObjectRequest
(
new
URL
(
url
),
null
),
new
File
(
savePath
));
System
.
err
.
println
(
a
);
// new File("C:\\Users\\Lenovo\\Desktop\\8小时\\test2.pdf"));
// // 带进度条的下载。
// ossClient.getObject(new GetObjectRequest(bucketName, objectName).<GetObjectRequest>withProgressListener(
...
...
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