|
|
|
@ -6,10 +6,13 @@ import cn.hutool.http.HttpUtil; |
|
|
|
import com.biutag.supervision.mapper.FileBase64Mapper; |
|
|
|
import com.biutag.supervision.mapper.FileBase64Mapper; |
|
|
|
import com.biutag.supervision.pojo.entity.FileBase64; |
|
|
|
import com.biutag.supervision.pojo.entity.FileBase64; |
|
|
|
import com.biutag.supervision.util.ImgUtils; |
|
|
|
import com.biutag.supervision.util.ImgUtils; |
|
|
|
|
|
|
|
import com.github.tobato.fastdfs.domain.conn.TrackerConnectionManager; |
|
|
|
import com.github.tobato.fastdfs.domain.fdfs.StorePath; |
|
|
|
import com.github.tobato.fastdfs.domain.fdfs.StorePath; |
|
|
|
import com.github.tobato.fastdfs.service.FastFileStorageClient; |
|
|
|
import com.github.tobato.fastdfs.service.FastFileStorageClient; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
@ -18,12 +21,19 @@ import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.Base64; |
|
|
|
import java.util.Base64; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@RequiredArgsConstructor |
|
|
|
@RequiredArgsConstructor |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
public class FileService { |
|
|
|
public class FileService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String STORAGE_GROUP = "group1"; |
|
|
|
|
|
|
|
|
|
|
|
private final FastFileStorageClient fastFileStorageClient; |
|
|
|
private final FastFileStorageClient fastFileStorageClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final TrackerConnectionManager trackerConnectionManager; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Environment environment; |
|
|
|
|
|
|
|
|
|
|
|
private final FileBase64Mapper fileBase64Mapper; |
|
|
|
private final FileBase64Mapper fileBase64Mapper; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${fdfs.preview-url}") |
|
|
|
@Value("${fdfs.preview-url}") |
|
|
|
@ -34,8 +44,24 @@ public class FileService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String upload(InputStream is, long size, String fileExtName) { |
|
|
|
public String upload(InputStream is, long size, String fileExtName) { |
|
|
|
StorePath storePath = fastFileStorageClient.uploadFile("group1", is, size, fileExtName); |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
return "/" + storePath.getFullPath(); |
|
|
|
String activeProfiles = String.join(",", environment.getActiveProfiles()); |
|
|
|
|
|
|
|
log.info("FastDFS上传开始: activeProfiles={}, trackerList={}, group={}, fileSize={}, fileExtName={}", |
|
|
|
|
|
|
|
activeProfiles, trackerConnectionManager.getTrackerList(), STORAGE_GROUP, size, fileExtName); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
StorePath storePath = fastFileStorageClient.uploadFile(STORAGE_GROUP, is, size, fileExtName); |
|
|
|
|
|
|
|
String filePath = "/" + storePath.getFullPath(); |
|
|
|
|
|
|
|
log.info("FastDFS上传成功: activeProfiles={}, trackerList={}, group={}, filePath={}, elapsedMs={}", |
|
|
|
|
|
|
|
activeProfiles, trackerConnectionManager.getTrackerList(), STORAGE_GROUP, filePath, |
|
|
|
|
|
|
|
System.currentTimeMillis() - startTime); |
|
|
|
|
|
|
|
return filePath; |
|
|
|
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
|
|
|
|
log.error("FastDFS上传失败: activeProfiles={}, trackerList={}, group={}, fileSize={}, fileExtName={}, " + |
|
|
|
|
|
|
|
"elapsedMs={}, exceptionType={}, message={}", |
|
|
|
|
|
|
|
activeProfiles, trackerConnectionManager.getTrackerList(), STORAGE_GROUP, size, fileExtName, |
|
|
|
|
|
|
|
System.currentTimeMillis() - startTime, e.getClass().getName(), e.getMessage(), e); |
|
|
|
|
|
|
|
throw e; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String uploadBase64(String base64, String originalFilename) { |
|
|
|
public String uploadBase64(String base64, String originalFilename) { |
|
|
|
|