1.取消音视频上传长度限制
2.更新minio版本
This commit is contained in:
parent
191882376c
commit
025388cc86
@ -19,13 +19,6 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- sauronsoftware start -->
|
||||
<dependency>
|
||||
<groupId>it.sauronsoftware</groupId>
|
||||
<artifactId>jave</artifactId>
|
||||
</dependency>
|
||||
<!-- sauronsoftware end -->
|
||||
|
||||
<!-- thumbnailator start -->
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
@ -39,6 +32,7 @@
|
||||
<artifactId>minio</artifactId>
|
||||
</dependency>
|
||||
<!-- minio end -->
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -3,7 +3,6 @@ package ink.wgink.module.file.controller.api;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.properties.FileProperties;
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.pojo.dtos.FileDTO;
|
||||
import ink.wgink.module.file.pojo.dtos.FileInfoDTO;
|
||||
@ -17,7 +16,6 @@ import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
@ -40,8 +38,6 @@ public class FileController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IFileService fileService;
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@ApiOperation(value = "文件分页列表", notes = "文件分页列表接口")
|
||||
@ApiImplicitParams({
|
||||
@ -104,9 +100,6 @@ public class FileController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadvideo")
|
||||
public Callable<SuccessResultData<String>> uploadVideo(@RequestParam("video") MultipartFile video) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getBackend() != null) {
|
||||
fileService.checkVideoDurationAllow(video, fileProperties.getMediaMaxDuration().getBackend().getVideo());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return asyncUploadSingle(video, UploadTypeEnum.VIDEO, params);
|
||||
}
|
||||
@ -118,9 +111,6 @@ public class FileController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadaudio")
|
||||
public Callable<SuccessResultData<String>> uploadAudio(@RequestParam("audio") MultipartFile audio) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getBackend() != null) {
|
||||
fileService.checkAudioDurationAllow(audio, fileProperties.getMediaMaxDuration().getBackend().getAudio());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return asyncUploadSingle(audio, UploadTypeEnum.AUDIO, params);
|
||||
}
|
||||
|
@ -37,8 +37,6 @@ public class FileAppController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IFileService fileService;
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@ApiOperation(value = "上传文件", notes = "上传文件接口")
|
||||
@ApiImplicitParams({
|
||||
@ -96,9 +94,6 @@ public class FileAppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadvideo")
|
||||
public Callable<SuccessResultData<String>> uploadVideo(@RequestHeader("token") String token, @RequestParam("video") MultipartFile video) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getApp() != null) {
|
||||
fileService.checkVideoDurationAllow(video, fileProperties.getMediaMaxDuration().getApp().getVideo());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return asyncUploadSingle(token, video, UploadTypeEnum.VIDEO, params);
|
||||
}
|
||||
@ -111,9 +106,6 @@ public class FileAppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-video-release/{userId}")
|
||||
public Callable<SuccessResultData<String>> uploadVideoByUserId(@PathVariable("userId") String userId, @RequestParam("video") MultipartFile video) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getApp() != null) {
|
||||
fileService.checkVideoDurationAllow(video, fileProperties.getMediaMaxDuration().getApp().getVideo());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return asyncUploadSingleByUserId(userId, video, UploadTypeEnum.VIDEO, params);
|
||||
}
|
||||
@ -126,9 +118,6 @@ public class FileAppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadaudio")
|
||||
public Callable<SuccessResultData<String>> uploadAudio(@RequestHeader("token") String token, @RequestParam("audio") MultipartFile audio) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getApp() != null) {
|
||||
fileService.checkAudioDurationAllow(audio, fileProperties.getMediaMaxDuration().getApp().getAudio());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return asyncUploadSingle(token, audio, UploadTypeEnum.AUDIO, params);
|
||||
}
|
||||
@ -141,9 +130,6 @@ public class FileAppController extends DefaultBaseController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("upload-audio-release/{userId}")
|
||||
public Callable<SuccessResultData<String>> uploadAudioByUserId(@PathVariable("userId") String userId, @RequestParam("audio") MultipartFile audio) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getApp() != null) {
|
||||
fileService.checkAudioDurationAllow(audio, fileProperties.getMediaMaxDuration().getApp().getAudio());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return asyncUploadSingleByUserId(userId, audio, UploadTypeEnum.AUDIO, params);
|
||||
}
|
||||
|
@ -263,19 +263,4 @@ public interface IFileService {
|
||||
*/
|
||||
List<FilePO> listPO(List<String> idList);
|
||||
|
||||
/**
|
||||
* 校验视频长度是否符合
|
||||
*
|
||||
* @param uploadFile
|
||||
* @param maxDuration
|
||||
*/
|
||||
void checkVideoDurationAllow(MultipartFile uploadFile, long maxDuration);
|
||||
|
||||
/**
|
||||
* 校验音频长度是否符合
|
||||
*
|
||||
* @param uploadFile
|
||||
* @param maxDuration
|
||||
*/
|
||||
void checkAudioDurationAllow(MultipartFile uploadFile, long maxDuration);
|
||||
}
|
||||
|
@ -25,21 +25,15 @@ import ink.wgink.properties.FileProperties;
|
||||
import ink.wgink.util.ResourceUtil;
|
||||
import ink.wgink.util.UUIDUtil;
|
||||
import ink.wgink.util.map.HashMapUtil;
|
||||
import it.sauronsoftware.jave.Encoder;
|
||||
import it.sauronsoftware.jave.EncoderException;
|
||||
import it.sauronsoftware.jave.MultimediaInfo;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItem;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@ -55,7 +49,6 @@ public class FileServiceImpl extends DefaultBaseService implements IFileService
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FileServiceImpl.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
@Autowired
|
||||
@ -280,46 +273,6 @@ public class FileServiceImpl extends DefaultBaseService implements IFileService
|
||||
return fileDao.getPO(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkVideoDurationAllow(MultipartFile uploadFile, long maxDuration) {
|
||||
if (maxDuration <= 0) {
|
||||
return;
|
||||
}
|
||||
checkDurationAllow(uploadFile, maxDuration, "视频");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkAudioDurationAllow(MultipartFile uploadFile, long maxDuration) {
|
||||
if (maxDuration <= 0) {
|
||||
return;
|
||||
}
|
||||
checkDurationAllow(uploadFile, maxDuration, "音频");
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验音、视频长度是否符合
|
||||
*
|
||||
* @param uploadFile
|
||||
* @param maxDuration
|
||||
*/
|
||||
private void checkDurationAllow(MultipartFile uploadFile, long maxDuration, String name) {
|
||||
CommonsMultipartFile commonsMultipartFile = (CommonsMultipartFile) uploadFile;
|
||||
DiskFileItem diskFileItem = (DiskFileItem) commonsMultipartFile.getFileItem();
|
||||
File source = diskFileItem.getStoreLocation();
|
||||
Encoder encoder = new Encoder();
|
||||
MultimediaInfo multimediaInfo;
|
||||
try {
|
||||
multimediaInfo = encoder.getInfo(source);
|
||||
} catch (EncoderException e) {
|
||||
e.printStackTrace();
|
||||
throw new SystemException("文件解析错误", e);
|
||||
}
|
||||
long fileDuration = multimediaInfo.getDuration() / 1000;
|
||||
if (fileDuration > maxDuration) {
|
||||
throw new FileException(name + "时间超过 " + maxDuration + " 秒");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* uEditor文件列表
|
||||
*
|
||||
|
@ -12,8 +12,7 @@ import ink.wgink.properties.FileMinIoProperties;
|
||||
import ink.wgink.properties.FileProperties;
|
||||
import ink.wgink.util.UUIDUtil;
|
||||
import ink.wgink.util.request.StaticResourceRequestUtil;
|
||||
import io.minio.MinioClient;
|
||||
import io.minio.PutObjectOptions;
|
||||
import io.minio.*;
|
||||
import io.minio.errors.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.joda.time.DateTime;
|
||||
@ -51,14 +50,16 @@ public class MinIoFileServiceImpl extends DefaultBaseService implements IMinIoFi
|
||||
private FileMinIoProperties minIoProperties;
|
||||
private MinioClient minioClient;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws InvalidPortException, InvalidEndpointException {
|
||||
public void init() {
|
||||
if (!fileProperties.getUseMinIo()) {
|
||||
return;
|
||||
}
|
||||
minIoProperties = fileProperties.getMinIo();
|
||||
minioClient = new MinioClient(minIoProperties.getEndpoint(), minIoProperties.getAccessKey(), minIoProperties.getSecretKey(), minIoProperties.getSecure());
|
||||
minioClient = MinioClient.builder()
|
||||
.endpoint(minIoProperties.getEndpoint())
|
||||
.credentials(minIoProperties.getAccessKey(), minIoProperties.getSecretKey())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -117,7 +118,8 @@ public class MinIoFileServiceImpl extends DefaultBaseService implements IMinIoFi
|
||||
if (!isOpen) {
|
||||
// 下载
|
||||
response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(filePO.getFileName(), "UTF-8"));
|
||||
inputStream = minioClient.getObject(filePO.getFileUrl(), objectName);
|
||||
GetObjectArgs getObjectArgs = GetObjectArgs.builder().bucket(filePO.getFileUrl()).object(objectName).build();
|
||||
inputStream = minioClient.getObject(getObjectArgs);
|
||||
} else {
|
||||
// 直接打开
|
||||
response.setHeader("Content-Disposition", "inline;fileName=" + URLEncoder.encode(filePO.getFileName(), "UTF-8"));
|
||||
@ -153,9 +155,9 @@ public class MinIoFileServiceImpl extends DefaultBaseService implements IMinIoFi
|
||||
endRange = Long.valueOf(rangeArray[1]);
|
||||
}
|
||||
setRangeHeader(startRange, endRange, response, filePO.getFileId(), contentLength);
|
||||
inputStream = minioClient.getObject(filePO.getFileUrl(), objectName, startRange, endRange);
|
||||
inputStream = minioClient.getObject(GetObjectArgs.builder().bucket(filePO.getFileUrl()).object(objectName).offset(startRange).length(endRange - startRange).build());
|
||||
} else {
|
||||
inputStream = minioClient.getObject(filePO.getFileUrl(), objectName);
|
||||
inputStream = minioClient.getObject(GetObjectArgs.builder().bucket(filePO.getFileUrl()).object(objectName).build());
|
||||
}
|
||||
if (endRange == contentLength - 1) {
|
||||
isDownloadComplete = true;
|
||||
@ -167,7 +169,7 @@ public class MinIoFileServiceImpl extends DefaultBaseService implements IMinIoFi
|
||||
}
|
||||
outputStream.flush();
|
||||
inputStream.close();
|
||||
} catch (IOException | ErrorResponseException | InsufficientDataException | InternalException | InvalidBucketNameException | InvalidKeyException | InvalidResponseException | NoSuchAlgorithmException | XmlParserException e) {
|
||||
} catch (ServerException | IOException | ErrorResponseException | InsufficientDataException | InternalException | InvalidKeyException | InvalidResponseException | NoSuchAlgorithmException | XmlParserException e) {
|
||||
throw new FileException("文件输出异常", e);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
@ -193,11 +195,10 @@ public class MinIoFileServiceImpl extends DefaultBaseService implements IMinIoFi
|
||||
private void upload(String uploadFileName, long fileSize, String bucketName, MultipartFile uploadFile) {
|
||||
try (InputStream inputStream = uploadFile.getInputStream()) {
|
||||
// 创建桶
|
||||
if (!minioClient.bucketExists(bucketName)) {
|
||||
minioClient.makeBucket(bucketName);
|
||||
if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) {
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||
}
|
||||
PutObjectOptions putObjectOptions = new PutObjectOptions(fileSize, PutObjectOptions.MAX_PART_SIZE);
|
||||
minioClient.putObject(bucketName, uploadFileName, inputStream, putObjectOptions);
|
||||
minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(uploadFileName).stream(inputStream, fileSize, -1).contentType(uploadFile.getContentType()).build());
|
||||
} catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) {
|
||||
throw new SystemException(e);
|
||||
}
|
||||
|
@ -1,12 +1,3 @@
|
||||
import ink.wgink.util.request.StaticResourceRequestUtil;
|
||||
import io.minio.MinioClient;
|
||||
import io.minio.PutObjectOptions;
|
||||
import io.minio.errors.MinioException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @ClassName: MinIOTest
|
||||
* @Description:
|
||||
@ -17,31 +8,7 @@ import java.io.InputStream;
|
||||
public class MinIOTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
// 使用MinIO服务的URL,端口,Access key和Secret key创建一个MinioClient对象
|
||||
MinioClient minioClient = new MinioClient("http://192.168.0.188:19001", "demotest", "demotest", false);
|
||||
// 检查存储桶是否已经存在
|
||||
boolean isExist = minioClient.bucketExists("images");
|
||||
if (isExist) {
|
||||
System.out.println("Bucket already exists.");
|
||||
} else {
|
||||
// 创建一个名为asiatrip的存储桶,用于存储照片的zip文件。
|
||||
minioClient.makeBucket("images");
|
||||
}
|
||||
// 使用putObject上传一个文件到存储桶中。
|
||||
File file = new File("/Users/wanggeng/Desktop/UploadFiles/images/20210820/1.jpeg");
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
PutObjectOptions putObjectOptions = new PutObjectOptions(file.length(), PutObjectOptions.MAX_PART_SIZE);
|
||||
// 下载
|
||||
// putObjectOptions.setContentType("application/octet-stream");
|
||||
// 直接打开
|
||||
String contentType = StaticResourceRequestUtil.getContentType("jpeg");
|
||||
putObjectOptions.setContentType(contentType);
|
||||
minioClient.putObject("images", "demo.jpeg", inputStream, putObjectOptions);
|
||||
System.out.println("successfully uploaded");
|
||||
} catch (MinioException e) {
|
||||
System.out.println("Error occurred: " + e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
2
pom.xml
2
pom.xml
@ -91,7 +91,7 @@
|
||||
<slf4j.version>1.7.30</slf4j.version>
|
||||
<activiti.version>6.0.0</activiti.version>
|
||||
<xmlgraphics.version>1.10</xmlgraphics.version>
|
||||
<minio.version>7.0.2</minio.version>
|
||||
<minio.version>8.2.1</minio.version>
|
||||
<mongo.version>3.2.5</mongo.version>
|
||||
<redis.version>2.5.5</redis.version>
|
||||
<freemarker.version>2.3.31</freemarker.version>
|
||||
|
Loading…
Reference in New Issue
Block a user