Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
ftp_pic
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
李辅翼
ftp_pic
Commits
b21fef76
Commit
b21fef76
authored
Jul 03, 2019
by
牟邦恺
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
add fdfs
parent
ccb30c8c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
0 deletions
+80
-0
pom.xml
+5
-0
src/main/java/com/hikcreate/service/fdfs/FastDFSClient.java
+65
-0
src/main/resources/application.properties
+10
-0
No files found.
pom.xml
View file @
b21fef76
...
...
@@ -73,6 +73,11 @@
<artifactId>
commons-lang3
</artifactId>
<version>
3.5
</version>
</dependency>
<dependency>
<groupId>
com.github.tobato
</groupId>
<artifactId>
fastdfs-client
</artifactId>
<version>
1.26.5
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/hikcreate/service/fdfs/FastDFSClient.java
0 → 100644
View file @
b21fef76
package
com
.
hikcreate
.
service
.
fdfs
;
import
com.github.tobato.fastdfs.domain.fdfs.StorePath
;
import
com.github.tobato.fastdfs.domain.proto.storage.DownloadByteArray
;
import
com.github.tobato.fastdfs.service.FastFileStorageClient
;
import
org.apache.commons.io.FilenameUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
/**
* @author 赵东
* @create 2019/3/22 16:32
*/
@Component
public
class
FastDFSClient
{
@Autowired
private
FastFileStorageClient
storageClient
;
/**
* 上传文件
*
* @param file 文件对象
* @return 文件访问地址
* @throws IOException
*/
public
String
uploadFile
(
MultipartFile
file
)
throws
IOException
{
StorePath
storePath
=
storageClient
.
uploadFile
(
file
.
getInputStream
(),
file
.
getSize
(),
FilenameUtils
.
getExtension
(
file
.
getOriginalFilename
()),
null
);
return
storePath
.
getFullPath
();
}
/**
* 上传文件
*
* @param file 文件对象
* @return 文件访问地址
* @throws IOException
*/
public
String
uploadFile
(
byte
[]
file
,
String
fileName
)
throws
IOException
{
StorePath
storePath
=
storageClient
.
uploadFile
(
new
ByteArrayInputStream
(
file
),
file
.
length
,
FilenameUtils
.
getExtension
(
fileName
),
null
);
return
storePath
.
getFullPath
();
}
/**
* 封装图片完整URL地址
*
* @param storePath
* @return
* @link https://blog.csdn.net/ityqing/article/details/81384740
*/
private
String
getResAccessUrl
(
StorePath
storePath
)
{
String
fileUrl
=
storePath
.
getFullPath
();
return
fileUrl
;
}
public
byte
[]
download
(
String
fileUrl
)
{
int
idx
=
fileUrl
.
indexOf
(
"/"
,
1
);
String
group
=
fileUrl
.
substring
(
1
,
idx
);
String
path
=
fileUrl
.
substring
(
idx
+
1
);
return
storageClient
.
downloadFile
(
group
,
path
,
new
DownloadByteArray
());
}
}
src/main/resources/application.properties
View file @
b21fef76
...
...
@@ -4,6 +4,16 @@ password=zckj2018
roundDay
=
-5
redis.cluster
=
172.16.25.23:7000,172.16.25.23:7001,172.16.25.23:7002,172.16.25.24:7003,172.16.25.24:7004,172.16.25.24:7005
redis.server
=
172.16.25.23:7000,172.16.25.23:7001,172.16.25.23:7002,172.16.25.24:7003,172.16.25.24:7004,172.16.25.24:7005
#fdfs
fdfs.so-timeout
=
1500
fdfs.connect-timeout
=
600
fdfs.thumb-image.width
=
150
fdfs.thumb-image.height
=
150
fdfs.tracker-list[0]
=
10.197.236.172
:
22122
fdfs.tracker-list[1]
=
10.197.236.188
:
22122
fdfs.pool.max-total
=
153
fdfs.pool.max-wait-millis
=
102
...
...
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