Commit da3faee0 authored by yaobaizheng's avatar yaobaizheng

文件上传速度问题

parent e6b2e0c9
...@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; ...@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.lyy.admin.common.utils.hwobs.ObsUtils; import com.lyy.admin.common.utils.hwobs.ObsUtils;
import com.lyy.admin.moudle.system.service.UploadService; import com.lyy.admin.moudle.system.service.UploadService;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
...@@ -11,10 +12,7 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -11,10 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -26,6 +24,9 @@ public class UploadServiceImpl implements UploadService { ...@@ -26,6 +24,9 @@ public class UploadServiceImpl implements UploadService {
@Value("${huaweiObs.bucketName}") @Value("${huaweiObs.bucketName}")
String bucketName; String bucketName;
@Value("${lyy.tempFilePath}")
String tempFilePath;
@Resource @Resource
private ObsUtils obsUtils; private ObsUtils obsUtils;
...@@ -42,12 +43,22 @@ public class UploadServiceImpl implements UploadService { ...@@ -42,12 +43,22 @@ public class UploadServiceImpl implements UploadService {
} }
String fileOriginalName = files.getOriginalFilename(); String fileOriginalName = files.getOriginalFilename();
String fileLastType = fileOriginalName.substring(files.getOriginalFilename().lastIndexOf(".")); String fileLastType = fileOriginalName.substring(files.getOriginalFilename().lastIndexOf("."));
// String date = LocalDateTimeUtils.formatNow("yyyy-MM-dd");
String date = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd"); String date = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd");
String newFilename = IdUtil.simpleUUID() + fileLastType; String newFilename = IdUtil.simpleUUID() + fileLastType;
String filePath = "/" + date + "/" + newFilename; String filePath = "/" + date + "/" + newFilename;
//将MultipartFile转为File,存储为本地临时文件
String localDir = tempFilePath + newFilename;
File file = new File(localDir);
InputStream inputStream = files.getInputStream(); InputStream inputStream = files.getInputStream();
obsUtils.ObsUpload(bucketName, rootPath + filePath, inputStream); FileUtils.copyInputStreamToFile(inputStream, file);
InputStream inputStream1 = new FileInputStream(localDir);
obsUtils.ObsUpload(bucketName, rootPath + filePath, inputStream1);
//删除临时文件
FileUtils.delete(file);
return rootPath + filePath; return rootPath + filePath;
} }
......
...@@ -58,6 +58,8 @@ spring: ...@@ -58,6 +58,8 @@ spring:
lyy: lyy:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath) # 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile: /home/liyeyun/uploadPath profile: /home/liyeyun/uploadPath
# 临时文件路径
tempFilePath: /home/liyeyun/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com) # 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
# obsPath: http://img-t.knowingindustry.com # obsPath: http://img-t.knowingindustry.com
obsPath: https://cfld-hw-obs-01.obs.cn-north-4.myhuaweicloud.com obsPath: https://cfld-hw-obs-01.obs.cn-north-4.myhuaweicloud.com
......
...@@ -58,6 +58,8 @@ spring: ...@@ -58,6 +58,8 @@ spring:
lyy: lyy:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath) # 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile: D:/uploadPath profile: D:/uploadPath
# 临时文件路径
tempFilePath: D:/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com) # 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
obsPath: http://img-t.knowingindustry.com obsPath: http://img-t.knowingindustry.com
#密码盐 #密码盐
......
...@@ -58,6 +58,8 @@ spring: ...@@ -58,6 +58,8 @@ spring:
lyy: lyy:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath) # 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile: /home/liyeyun/uploadPath profile: /home/liyeyun/uploadPath
# 临时文件路径
tempFilePath: /home/liyeyun/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com) # 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
obsPath: https://cfld-hw-obs-01.obs.cn-north-4.myhuaweicloud.com obsPath: https://cfld-hw-obs-01.obs.cn-north-4.myhuaweicloud.com
#密码盐 #密码盐
......
...@@ -58,6 +58,8 @@ spring: ...@@ -58,6 +58,8 @@ spring:
lyy: lyy:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath) # 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile: /home/liyeyun/uploadPath profile: /home/liyeyun/uploadPath
# 临时文件路径
tempFilePath: /home/liyeyun/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com) # 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
obsPath: https://cfld-hw-obs-01.obs.cn-north-4.myhuaweicloud.com obsPath: https://cfld-hw-obs-01.obs.cn-north-4.myhuaweicloud.com
#密码盐 #密码盐
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment