1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package com.xjrsoft.common.factory;
- import com.xjrsoft.common.utils.DateUtils;
- import com.xjrsoft.config.OSSConfig;
- import org.apache.commons.lang.StringUtils;
- import java.io.InputStream;
- import java.util.Date;
- import java.util.UUID;
- /**
- * 云存储(支持七牛、阿里云、腾讯云、华为)
- *
- * @author tzx
- */
- public abstract class CloudStorageService {
- /** 云存储配置信息 */
- OSSConfig config;
- /**
- * 文件路径
- * @param prefix 前缀
- * @param suffix 后缀
- * @return 返回上传路径
- */
- public String getPath(String prefix, String suffix) {
- //生成uuid
- String uuid = UUID.randomUUID().toString().replaceAll("-", "");
- //文件路径
- String path = DateUtils.format(new Date(), "yyyyMMdd") + "/" + uuid;
- if(StringUtils.isNotBlank(prefix)){
- path = prefix + "/" + path;
- }
- return path + suffix;
- }
- /**
- * 文件上传
- * @param data 文件字节数组
- * @param path 文件路径,包含文件名
- * @return 返回http地址
- */
- public abstract String upload(byte[] data, String path);
- /**
- * 文件上传
- * @param data 文件字节数组
- * @param suffix 后缀
- * @return 返回http地址
- */
- public abstract String uploadSuffix(byte[] data, String suffix);
- /**
- * 文件上传
- * @param inputStream 字节流
- * @param path 文件路径,包含文件名
- * @return 返回http地址
- */
- public abstract String upload(InputStream inputStream, String path);
- /**
- * 文件上传
- * @param inputStream 字节流
- * @param suffix 后缀
- * @return 返回http地址
- */
- public abstract String uploadSuffix(InputStream inputStream, String suffix);
- public abstract boolean delete(String objectName );
- }
|