批量下载技术监督反馈文件
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package com.njcn.oss.utils;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.huawei.obs.util.OBSUtil;
|
||||
@@ -17,7 +15,6 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
|
||||
@@ -90,7 +87,7 @@ public class FileStorageUtil {
|
||||
} else {
|
||||
try {
|
||||
//把名称存入数据
|
||||
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.uploadStream(fileStream, minIossProperties.getBucket(), dir,minIoUtils.minFileName(fileName));
|
||||
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.uploadStream(fileStream, minIossProperties.getBucket(), dir, minIoUtils.minFileName(fileName));
|
||||
filePath = minIoUploadResDTO.getMinFileName();
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
||||
@@ -106,7 +103,7 @@ public class FileStorageUtil {
|
||||
* @date 2023/3/7 23:04
|
||||
* @param filePath 文件在服务器的路径
|
||||
*/
|
||||
public String getFileUrl(String filePath){
|
||||
public String getFileUrl(String filePath) {
|
||||
String url;
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
url = obsUtil.getFileUrl(filePath);
|
||||
@@ -117,14 +114,13 @@ public class FileStorageUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* 根据文件路径获取文件流
|
||||
* @author hongawen
|
||||
* @date 2023/3/7 23:04
|
||||
* @param filePath 文件在服务器的路径
|
||||
*/
|
||||
public InputStream getFileStream(String filePath){
|
||||
public InputStream getFileStream(String filePath) {
|
||||
InputStream inputStream;
|
||||
try {
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
@@ -132,7 +128,7 @@ public class FileStorageUtil {
|
||||
} else {
|
||||
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
||||
}
|
||||
}catch (Exception exception){
|
||||
} catch (Exception exception) {
|
||||
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
||||
}
|
||||
return inputStream;
|
||||
@@ -147,17 +143,17 @@ public class FileStorageUtil {
|
||||
public void downloadStream(HttpServletResponse response, String filePath) throws IOException {
|
||||
InputStream inputStream;
|
||||
OutputStream toClient = null;
|
||||
try{
|
||||
try {
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
inputStream = obsUtil.downloadStream(filePath);
|
||||
} else {
|
||||
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
||||
}
|
||||
}catch (Exception exception){
|
||||
} catch (Exception exception) {
|
||||
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
||||
}
|
||||
String fileType = filePath.substring(filePath.lastIndexOf('.')).toLowerCase();
|
||||
switch (fileType){
|
||||
switch (fileType) {
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
case "png":
|
||||
@@ -187,8 +183,26 @@ public class FileStorageUtil {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取下载文件流
|
||||
*
|
||||
* @param filePath
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public InputStream downloadStream(String filePath) {
|
||||
InputStream inputStream;
|
||||
try {
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
inputStream = obsUtil.downloadStream(filePath);
|
||||
} else {
|
||||
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
||||
}
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
/***
|
||||
* 根据文件路径删除指定文件对象
|
||||
@@ -196,10 +210,10 @@ public class FileStorageUtil {
|
||||
* @date 2023/3/8 9:25
|
||||
* @param fileName 文件路径名
|
||||
*/
|
||||
public void deleteFile(String fileName){
|
||||
public void deleteFile(String fileName) {
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
obsUtil.delete(fileName);
|
||||
}else{
|
||||
} else {
|
||||
minIoUtils.removeObject(minIossProperties.getBucket(), fileName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user