|
|
|
@ -2,22 +2,18 @@ package com.bnyer.file.service; |
|
|
|
|
|
|
|
import com.bnyer.common.core.exception.ServiceException; |
|
|
|
import com.bnyer.file.config.MinioConfig; |
|
|
|
import com.bnyer.file.utils.FileUploadUtils; |
|
|
|
import com.bnyer.file.utils.ImgUtil; |
|
|
|
import io.minio.ObjectStat; |
|
|
|
import io.minio.MinioClient; |
|
|
|
import io.minio.PutObjectArgs; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import net.coobird.thumbnailator.Thumbnails; |
|
|
|
import org.apache.commons.compress.utils.IOUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import com.bnyer.file.utils.FileUploadUtils; |
|
|
|
import io.minio.MinioClient; |
|
|
|
import io.minio.PutObjectArgs; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.net.URLEncoder; |
|
|
|
|
|
|
|
/** |
|
|
|
* Minio 文件存储 |
|
|
|
@ -26,8 +22,7 @@ import java.net.URLEncoder; |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class MinioSysFileServiceImpl implements MinioService |
|
|
|
{ |
|
|
|
public class MinioSysFileServiceImpl implements MinioService { |
|
|
|
@Autowired |
|
|
|
private MinioConfig minioConfig; |
|
|
|
|
|
|
|
@ -42,8 +37,7 @@ public class MinioSysFileServiceImpl implements MinioService |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String uploadFile(MultipartFile file) throws Exception |
|
|
|
{ |
|
|
|
public String uploadFile(MultipartFile file) throws Exception { |
|
|
|
String fileName = FileUploadUtils.extractFilename(file); |
|
|
|
PutObjectArgs args = PutObjectArgs.builder() |
|
|
|
.bucket(minioConfig.getBucketName()) |
|
|
|
@ -57,15 +51,24 @@ public class MinioSysFileServiceImpl implements MinioService |
|
|
|
|
|
|
|
@Override |
|
|
|
public String uploadBanner(MultipartFile file) throws Exception { |
|
|
|
String fileName = FileUploadUtils.extractFilename(file); |
|
|
|
PutObjectArgs args = PutObjectArgs.builder() |
|
|
|
.bucket("tiktok") |
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
String[] split = fileName.split("\\."); |
|
|
|
if (split.length > 1) { |
|
|
|
fileName = split[0] + "_" + System.currentTimeMillis() + "." + split[1]; |
|
|
|
} else { |
|
|
|
fileName = fileName + System.currentTimeMillis(); |
|
|
|
} |
|
|
|
InputStream in = null; |
|
|
|
in = file.getInputStream(); |
|
|
|
client.putObject(PutObjectArgs.builder() |
|
|
|
.bucket(minioConfig.getBucketName()) |
|
|
|
.object(fileName) |
|
|
|
.stream(file.getInputStream(), file.getSize(), -1) |
|
|
|
.stream(in, in.available(), -1) |
|
|
|
.contentType(file.getContentType()) |
|
|
|
.build(); |
|
|
|
client.putObject(args); |
|
|
|
.build() |
|
|
|
); |
|
|
|
return minioConfig.getUrl()+ "/" + minioConfig.getBucketName() + "/" + fileName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|