package com.zteits.pay.util; import com.clouds.common.oss.base.OssClientBaseWrapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.io.InputStream; /** * Copyright: Copyright (c) 2017 zteits * * @ClassName: com.clouds.common.fastdfs * @Description: FastDFS文件上传下载包装类 * @version: v1.0.0 * @author: atao * @date: 2017/11/29 下午4:53 * Modification History: * Date Author Version Description * ---------------------------------------------------------* * 2017/11/29 atao v1.0.0 创建 */ @Component public class FastDFSClientWrapper extends OssClientBaseWrapper { private final Logger logger = LoggerFactory.getLogger(FastDFSClientWrapper.class); /** * 上传文件 * * @param file 文件对象 * @return 文件访问地址 * @throws IOException */ public String uploadFile(MultipartFile file) throws IOException { String storePath = getOssClientService().uploadFile(file); logger.info("获取的存储路径为{}", storePath); return storePath; } public String uploadFile(InputStream inputStream, long fileSize, String fileExtName) { String storePath = getOssClientService().uploadFile(inputStream, fileExtName, fileSize); logger.info("获取的存储路径为{}", storePath); return storePath; } /** * 上传 APP 文件(第二百七十八切片补入)。 * *
逐字搬自老 {@code zteits-bcp-portal} 的 * {@code com.zteits.bcp.portal.util.FastDFSClientWrapper#uploadAppFile(MultipartFile)} * (唯二差别:老类用 dubbo 版 {@code StringUtils},本方法不涉及)。
* *⚠️ 与 {@link #uploadFile(MultipartFile)} 不是同一条路:这里故意调 * {@link #getFastDFSOssClientWrapper()} 强制走 FastDFS,不看数据库 * {@code FILE_OSS_CONFIG/ENABLE_TYPE} 选后端 —— 存量口径就是「APP 安装包固定放 FastDFS」。 * 改成 {@code getOssClientService()} 会把安装包写进阿里云 OSS,是行为变更。
*/ public String uploadAppFile(MultipartFile file) throws IOException { // app固定使用fastdfs保存 String filePath = getFastDFSOssClientWrapper().uploadFile(file); logger.info("获取的存储路径为{}", filePath); return filePath; } public String uploadBase64Pic(String base64Str, String fileExtension, Long orgId, String plNo) { String storePath = getOssClientService().uploadBase64Pic(base64Str, fileExtension, orgId, plNo); logger.info("获取的存储路径为{}", storePath); return storePath; } }