update 修改图片上传名称

This commit is contained in:
2023-11-22 16:49:23 +08:00
parent f3db2c289f
commit e6797f6016

View File

@@ -3,13 +3,13 @@ package com.jsowell.common.util.file;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.jsowell.common.config.AliyunOssConfig;
import com.jsowell.common.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
@Component
public class AliyunOssUploadUtils {
@@ -44,10 +44,10 @@ public class AliyunOssUploadUtils {
//获取当前时间
LocalDateTime currentDate = LocalDateTime.now();
String dir_name = currentDate.getYear() + "/" + currentDate.getMonthValue() + "/";
String dir_name = currentDate.getYear() + "/" + currentDate.getMonthValue() + "/" + currentDate.getDayOfMonth() + "/";
// 随机数
String randomNumber = RandomUtil.getRandomNumber(5) + "-";
String randomNumber = Long.toHexString(currentDate.toEpochSecond(ZoneOffset.UTC)) + "-";
// 文件路径名称
filePathName = aliyunOssConfig.getFilehost() + "/" + dir_name + randomNumber + filePathName;