| | |
| | | import org.dromara.system.service.ISysOssService; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | // 保存文件信息 |
| | | return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult); |
| | | } |
| | | |
| | | @Override |
| | | public SysOssVo upload(File file) { |
| | | String originalfileName = file.getName(); |
| | | String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); |
| | | OssClient storage = OssFactory.instance(); |
| | | UploadResult uploadResult = storage.uploadSuffix(file, suffix); |
| | | // 保存文件信息 |
| | | return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult); |
| | | } |
| | | |
| | | @NotNull |
| | | private SysOssVo buildResultEntity(String originalfileName, String suffix, String configKey, UploadResult uploadResult) { |
| | | SysOss oss = new SysOss(); |
| | | oss.setUrl(uploadResult.getUrl()); |
| | | oss.setFileSuffix(suffix); |
| | | oss.setFileName(uploadResult.getFilename()); |
| | | oss.setOriginalName(originalfileName); |
| | | oss.setService(storage.getConfigKey()); |
| | | oss.setService(configKey); |
| | | baseMapper.insert(oss); |
| | | SysOssVo sysOssVo = MapstructUtils.convert(oss, SysOssVo.class); |
| | | return this.matchingUrl(sysOssVo); |