FdfsUtils.java
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//package cn.com.glsx.auditstatistics.util;
//
//import cn.com.glsx.auditstatistics.config.FdfsProperty;
//import com.github.tobato.fastdfs.domain.fdfs.StorePath;
//import com.github.tobato.fastdfs.service.FastFileStorageClient;
//import org.apache.commons.io.FilenameUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//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;
//import java.io.InputStream;
//
///**
// * <p>Description: FastDFS 文件操作工具类
// * <p>Project: shop
// *
// * @author wbh
// * @date 2020-12-15
// */
//@Component
//public class FdfsUtils {
// private static final String FDFS_DOMAIN_PROP = "tracker-nginx-domain";
// private static final String DOMAIN_SEPARATOR = "/";
//
// private static final Logger logger = LoggerFactory.getLogger(FdfsUtils.class);
// private static FdfsProperty fdfsProperty;
// private static FastFileStorageClient storageClient;
//
// public static String uploadFile(MultipartFile multipartFile) throws IOException {
// String fileUrl;
// InputStream inputStream = multipartFile.getInputStream();
// long fileSize = multipartFile.getSize();
// String fileExtension = FilenameUtils.getExtension(multipartFile.getOriginalFilename());
// StorePath storePath = storageClient.uploadFile(inputStream, fileSize, fileExtension,
// null);
// fileUrl = getFileUrl(storePath);
// return fileUrl;
// }
//
// public static String uploadFile(byte[] bytes, String fileExtension) {
// ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
// StorePath storePath = storageClient.uploadFile(inputStream, bytes.length, fileExtension,
// null);
// String fileUrl = getFileUrl(storePath);
// return fileUrl;
// }
//
// public static String uploadFile(InputStream inputStream, String fileExtension)
// throws IOException {
// StorePath storePath = storageClient.uploadFile(inputStream, inputStream.available(),
// fileExtension, null);
// String fileUrl = getFileUrl(storePath);
// return fileUrl;
// }
//
// public static void deleteFile(String fileUrl) {
// if (StringUtils.isNoneBlank(fileUrl)) {
// StorePath storePath = StorePath.parseFromUrl(fileUrl);
// storageClient.deleteFile(storePath.getGroup(), storePath.getPath());
// }
// }
//
// private static String getFileUrl(StorePath storePath) {
// String domain = fdfsProperty.getTrackerNginxDomain();
// String fileUrl = domain + DOMAIN_SEPARATOR + storePath.getFullPath();
//
// return fileUrl;
// }
//
// @Autowired
// public void setFdfsProperty(FdfsProperty fdfsProperty) {
// FdfsUtils.fdfsProperty = fdfsProperty;
// }
//
// @Autowired
// public void setStorageClient(FastFileStorageClient storageClient) {
// FdfsUtils.storageClient = storageClient;
// }
//}