Commit b21fef76 by 牟邦恺

add fdfs

parent ccb30c8c
......@@ -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>
......
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());
}
}
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment