Commit da3faee0 authored by yaobaizheng's avatar yaobaizheng

文件上传速度问题

parent e6b2e0c9
......@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.lyy.admin.common.utils.hwobs.ObsUtils;
import com.lyy.admin.moudle.system.service.UploadService;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.FileCopyUtils;
......@@ -11,10 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
......@@ -26,6 +24,9 @@ public class UploadServiceImpl implements UploadService {
@Value("${huaweiObs.bucketName}")
String bucketName;
@Value("${lyy.tempFilePath}")
String tempFilePath;
@Resource
private ObsUtils obsUtils;
......@@ -42,12 +43,22 @@ public class UploadServiceImpl implements UploadService {
}
String fileOriginalName = files.getOriginalFilename();
String fileLastType = fileOriginalName.substring(files.getOriginalFilename().lastIndexOf("."));
// String date = LocalDateTimeUtils.formatNow("yyyy-MM-dd");
String date = DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd");
String newFilename = IdUtil.simpleUUID() + fileLastType;
String filePath = "/" + date + "/" + newFilename;
//将MultipartFile转为File,存储为本地临时文件
String localDir = tempFilePath + newFilename;
File file = new File(localDir);
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;
}
......
......@@ -58,6 +58,8 @@ spring:
lyy:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile: /home/liyeyun/uploadPath
# 临时文件路径
tempFilePath: /home/liyeyun/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
# obsPath: http://img-t.knowingindustry.com
obsPath: https://cfld-hw-obs-01.obs.cn-north-4.myhuaweicloud.com
......
......@@ -58,6 +58,8 @@ spring:
lyy:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile: D:/uploadPath
# 临时文件路径
tempFilePath: D:/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
obsPath: http://img-t.knowingindustry.com
#密码盐
......
......@@ -58,6 +58,8 @@ spring:
lyy:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile: /home/liyeyun/uploadPath
# 临时文件路径
tempFilePath: /home/liyeyun/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.com)
obsPath: https://cfld-hw-obs-01.obs.cn-north-4.myhuaweicloud.com
#密码盐
......
......@@ -58,6 +58,8 @@ spring:
lyy:
# 本地文件路径 示例( Windows配置D:/uploadPath,Linux配置 /home/uploadPath)
profile: /home/liyeyun/uploadPath
# 临时文件路径
tempFilePath: /home/liyeyun/uploadPath/temp/
# 华为OBS文件路径 示例( https://img-t.knowingindustry.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