/** * Copyright (c) 2018 人人开源 All rights reserved. * * https://www.renren.io * * 版权所有,侵权必究! */ package com.example.server.sysOss.service; import cn.hutool.core.date.DateUtil; import com.example.server.sysOss.model.SysOss; import org.apache.commons.lang3.StringUtils; import java.io.InputStream; import java.util.Date; import java.util.UUID; /** * 云存储 * * @author Mark sunlightcs@gmail.com */ public abstract class AbstractStorageService { /** * 文件路径 * * @param prefix 前缀 * @param suffix 后缀 * @return 返回上传路径 */ public String getPath(String prefix, String suffix) { // 生成uuid String uuid = UUID.randomUUID().toString().replaceAll("-", ""); // 文件路径 String path = DateUtil.format(new Date(), "yyyyMMdd") + "/" + uuid; if (StringUtils.isNotBlank(prefix)) { path = prefix + "/" + path; } return path + "." + suffix; } /** * 文件上传 * * @param data * 文件字节数组 * @param path * 文件路径,包含文件名 * @return 返回http地址 */ public abstract SysOss upload(byte[] data, String path); /** * 文件上传 * * @param data * 文件字节数组 * @param suffix * 后缀 * @return 返回http地址 */ public abstract SysOss uploadSuffix(byte[] data, String suffix); /** * 文件上传 * * @param inputStream * 字节流 * @param path * 文件路径,包含文件名 * @return 返回http地址 */ public abstract SysOss upload(InputStream inputStream, String path); /** * 文件上传 * * @param inputStream * 字节流 * @param suffix * 后缀 * @return 返回http地址 */ public abstract SysOss uploadSuffix(InputStream inputStream, String suffix); public abstract void delete(SysOss oss); }