|
|
@@ -1,19 +1,28 @@
|
|
|
package com.sqx.modules.file;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.aliyun.oss.OSS;
|
|
|
import com.aliyun.oss.OSSClientBuilder;
|
|
|
+import com.sqx.common.exception.SqxException;
|
|
|
import com.sqx.common.utils.Result;
|
|
|
+import com.sqx.config.MinioConfig;
|
|
|
import com.sqx.modules.common.service.CommonInfoService;
|
|
|
import com.sqx.modules.file.utils.FileUploadUtils;
|
|
|
import icu.xuyijie.secureapi.annotation.DecryptParam;
|
|
|
+import io.minio.MinioClient;
|
|
|
+import io.minio.ObjectWriteResponse;
|
|
|
+import io.minio.PutObjectArgs;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jaudiotagger.audio.AudioFileIO;
|
|
|
import org.jaudiotagger.audio.mp3.MP3AudioHeader;
|
|
|
import org.jaudiotagger.audio.mp3.MP3File;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
@@ -34,19 +43,16 @@ import java.util.UUID;
|
|
|
* @author fang
|
|
|
* @date 2020/7/13
|
|
|
*/
|
|
|
-@RestController
|
|
|
+@Slf4j
|
|
|
@Api(value = "阿里云文件上传", tags = {"阿里云文件上传"})
|
|
|
+@RestController
|
|
|
@RequestMapping(value = "/alioss")
|
|
|
-@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
public class AliFileUploadController {
|
|
|
|
|
|
-
|
|
|
private final CommonInfoService commonRepository;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- public AliFileUploadController(CommonInfoService commonRepository) {
|
|
|
- this.commonRepository = commonRepository;
|
|
|
- }
|
|
|
+ private final MinioClient minioClient;
|
|
|
+ private final MinioConfig minioConfig;
|
|
|
|
|
|
@RequestMapping(value = "/upload", method = RequestMethod.POST)
|
|
|
@ApiOperation("文件上传")
|
|
|
@@ -71,7 +77,24 @@ public class AliFileUploadController {
|
|
|
String src = commonRepository.findOne(72).getValue()+"/"+completePath;
|
|
|
// String src = commonRepository.findOne(19).getValue()+"/img/"+completePath;
|
|
|
return Result.success().put("data",src);
|
|
|
- }else{
|
|
|
+ } else if (StrUtil.equals(value, "3")) {
|
|
|
+ // Minio上传
|
|
|
+ String suffix = file.getOriginalFilename().substring(Objects.requireNonNull(file.getOriginalFilename()).lastIndexOf("."));
|
|
|
+ String completePath = getPath(suffix);
|
|
|
+ try {
|
|
|
+ minioClient.putObject(PutObjectArgs.builder()
|
|
|
+ .bucket(minioConfig.getBucket())
|
|
|
+ .object(completePath)
|
|
|
+ .stream(file.getInputStream(), file.getSize(), -1)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ String src = commonRepository.findOne(72).getValue() + "/" + completePath;
|
|
|
+ return Result.success().put("data", src);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new SqxException("文件上传失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ } else{
|
|
|
try
|
|
|
{
|
|
|
String http = commonRepository.findOne(19).getValue();
|