package com.kidgrow.filecenter.config; import cn.hutool.core.util.StrUtil; import com.aliyun.oss.model.OSSObject; import com.kidgrow.filecenter.model.FileInfo; import com.kidgrow.filecenter.properties.FileServerProperties; import com.kidgrow.filecenter.service.impl.AbstractIFileService; import com.github.tobato.fastdfs.domain.fdfs.StorePath; import com.github.tobato.fastdfs.service.FastFileStorageClient; import org.apache.commons.io.FilenameUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.InputStream; /** * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020
* * @Description: FastDfs配置
* @Project:
* @CreateDate: Created in 2020/2/18 11:24
* @Author: liuke */ @Configuration @ConditionalOnProperty(name = "kidgrow.file-server.type", havingValue = "fastdfs") public class FastdfsAutoConfigure { @Autowired private FileServerProperties fileProperties; @Service public class FastdfsServiceImpl extends AbstractIFileService { @Autowired private FastFileStorageClient storageClient; @Override protected String fileType() { return fileProperties.getType(); } @Override protected void uploadFile(MultipartFile file, FileInfo fileInfo) throws Exception { StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(), FilenameUtils.getExtension(file.getOriginalFilename()), null); fileInfo.setUrl("http://" + fileProperties.getFdfs().getWebUrl() + "/" + storePath.getFullPath()); fileInfo.setPath(storePath.getFullPath()); } @Override protected void fileUpLoadOss(FileInfo fileInfo, String newFilePath, InputStream fileStream,String fileFolder) { } @Override protected String FilePath(String imgType, String folderByDate,String hospitalId,String departmentId) { return null; } @Override protected OSSObject down(String url) { return null; } @Override protected boolean deleteFile(FileInfo fileInfo) { if (fileInfo != null && StrUtil.isNotEmpty(fileInfo.getPath())) { StorePath storePath = StorePath.parseFromUrl(fileInfo.getPath()); storageClient.deleteFile(storePath.getGroup(), storePath.getPath()); } return true; } } }