|
|
|
@ -43,9 +43,9 @@ public class UploadUtils { |
|
|
|
|
@Autowired |
|
|
|
|
private FileDao fileDao; |
|
|
|
|
|
|
|
|
|
public Map<String, String> upload(MultipartFile file, String md5) { |
|
|
|
|
public Map<String, Object> upload(MultipartFile file, String md5) { |
|
|
|
|
try { |
|
|
|
|
Map<String, String> objectMap = fileDao.listFileUrl(md5, 1); |
|
|
|
|
Map<String, Object> objectMap = fileDao.listFileUrl(md5, 1); |
|
|
|
|
if ( objectMap != null ){ |
|
|
|
|
objectMap.put("name", file.getOriginalFilename()); |
|
|
|
|
return objectMap; |
|
|
|
@ -56,8 +56,9 @@ public class UploadUtils { |
|
|
|
|
String fileName = UUID.randomUUID() + type; |
|
|
|
|
File desc = getAbsoluteFile(filePath, fileName); |
|
|
|
|
file.transferTo(desc); |
|
|
|
|
Map<String, String> pathFileName = getPathFileName(filePath, fileName, name, type); |
|
|
|
|
fileDao.addFile(md5, pathFileName.get("url"), Integer.parseInt(pathFileName.get("type")), 1); |
|
|
|
|
Map<String, Object> pathFileName = getPathFileName(filePath, fileName, name, type); |
|
|
|
|
fileDao.addFile(md5, pathFileName.get("url").toString(), |
|
|
|
|
Integer.parseInt(pathFileName.get("type").toString()), 1); |
|
|
|
|
return pathFileName; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error(e.getLocalizedMessage()); |
|
|
|
@ -65,8 +66,8 @@ public class UploadUtils { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String, String> getPathFileName(String uploadDir, String fileName, String name, String type) throws IOException { |
|
|
|
|
Map<String, String> map = new ConcurrentHashMap(3); |
|
|
|
|
private Map<String, Object> getPathFileName(String uploadDir, String fileName, String name, String type) throws IOException { |
|
|
|
|
Map<String, Object> map = new ConcurrentHashMap(3); |
|
|
|
|
int dirLastIndex = localtion.length() + 1; |
|
|
|
|
String currentDir = StringUtils.substring(uploadDir, dirLastIndex); |
|
|
|
|
String pathFileName = "/profile" + "/" + currentDir + "/" + fileName; |
|
|
|
@ -94,8 +95,8 @@ public class UploadUtils { |
|
|
|
|
* @param module oss目录 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public Map<String, String> upload(MultipartFile file, @Nullable String module, String md5) { |
|
|
|
|
Map<String, String> objectMap = fileDao.listFileUrl(md5, 2); |
|
|
|
|
public Map<String, Object> upload(MultipartFile file, @Nullable String module, String md5) { |
|
|
|
|
Map<String, Object> objectMap = fileDao.listFileUrl(md5, 2); |
|
|
|
|
if ( objectMap != null ){ |
|
|
|
|
objectMap.put("name", file.getOriginalFilename()); |
|
|
|
|
return objectMap; |
|
|
|
@ -112,7 +113,7 @@ public class UploadUtils { |
|
|
|
|
} |
|
|
|
|
String extension = "." + FilenameUtils.getExtension(file.getOriginalFilename()); |
|
|
|
|
String objectName = module + "/" + UUID.randomUUID().toString() + extension; |
|
|
|
|
Map<String, String> resultMap = new HashMap<>(); |
|
|
|
|
Map<String, Object> resultMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
// 创建OSSClient实例。
|
|
|
|
|
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); |
|
|
|
|