feat: 设置模糊路径

This commit is contained in:
wangyu 2021-04-07 11:41:19 +08:00
parent 02b6b411c7
commit 79602d0224
1 changed files with 4 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package com.flyfish.framework.file.service;
import com.flyfish.framework.file.config.UploadConfiguration;
import com.flyfish.framework.file.utils.SystemUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
@ -11,6 +12,7 @@ import javax.annotation.Resource;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.function.Supplier;
/**
@ -35,7 +37,8 @@ public class FileService {
*/
public Mono<String> saveLocal(FilePart part) {
String localPath = uploadConfiguration.getLocalPath();
String path = uploadConfiguration.path(generator) + "/" + part.filename();
String extend = StringUtils.substringAfterLast(part.filename(), ".");
String path = uploadConfiguration.path(generator) + "/" + UUID.randomUUID().toString() + "." + extend;
String fullPath = localPath + path;
SystemUtils.testPath(fullPath);
return part.transferTo(Paths.get(fullPath))