Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
ldp-docs
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
doc
ldp-docs
Commits
15983f68
Commit
15983f68
authored
Oct 12, 2020
by
马超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 新增第三方云存储服务使用文档
parent
4e1f12df
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+86
-0
OSS-profile.png
imgs/OSS-profile.png
+0
-0
LDP第三方对象存储服务使用说明.md
开发文档/LDP第三方对象存储服务使用说明.md
+86
-0
No files found.
imgs/OSS-profile.png
0 → 100644
View file @
15983f68
48.6 KB
开发文档/LDP第三方对象存储服务使用说明.md
0 → 100644
View file @
15983f68
# LDP第三方对象存储服务使用说明
相关配置和使用案例,已经更新到脚手架工程
[
**ldp-app-example**
](
http://gitlab.dev.shxrtech.com/ldp/ldp-app-example
)
,具体代码在example-biz模块中。
## 一、云对象存储介绍
云对象存储是一种基于互联网的简单对象存储服务,并提供简单易用的RESTFul接口,使用户在任何时间,任何地点都能通过互联网访问对象存储中的数据。LDP支持这几种对象存储,阿里云、minio、七牛云、腾讯云,并且根据配置文件来指定使用其中的一种方式。
## 二、使用方式
### 2.1 添加Maven依赖
这里用脚手架工程举例, 在example-biz模块 pom.xml中添加common-storage依赖
```
xml
<dependency>
<groupId>
com.sinra.ldp
</groupId>
<artifactId>
common-storage
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
```
### 2.2 添加对象存储配置
在配置文件中添加云储存配置,active-server指定激活哪一种对象存储的配置,下图中激活的是qiniu(七牛云)。这里只是示例,使用时只需要填写使用的那份配置就行。

每一种配置都有些许差异,请仔细填写。
### 2.3 服务调用
`StorageService`
有三个上传接口,分别是:
```
java
/**
* 上传文件到云存储, 返回下载HTTP地址
* @param data 字节数据
* @param fileName 文件名
* @return HTTP地址
* @throws Exception
*/
String
upload
(
byte
[]
data
,
String
fileName
)
throws
Exception
;
/**
* 上传文件到云存储, 返回下载HTTP地址
* @param inputStream 字节流
* @param fileName 文件名
* @return HTTP地址
* @throws Exception
*/
String
upload
(
InputStream
inputStream
,
String
fileName
)
throws
Exception
;
/**
* 上传文件到云存储, 返回下载HTTP地址
* @param file 文件
* @param fileName 文件名
* @return HTTP地址
* @throws Exception
*/
String
upload
(
File
file
,
String
fileName
)
throws
Exception
;
```
样例工程中使用的是byte
[]
,以下是样例代码:
```
java
//注入StorageService
@Autowired
StorageService
storageService
;
@Override
public
String
uploadToCloudStorage
(
MultipartFile
file
)
{
String
uploadPath
=
null
;
try
{
//调用上传方法,返回的是下载地址
uploadPath
=
storageService
.
upload
(
file
.
getBytes
(),
file
.
getOriginalFilename
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
//写入日志并抛出异常
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
BizException
(
500
,
e
.
getMessage
());
}
return
uploadPath
;
}
```
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