|
|
@ -3,7 +3,9 @@ package com.bnyer.file.service; |
|
|
import com.bnyer.common.core.exception.ServiceException; |
|
|
import com.bnyer.common.core.exception.ServiceException; |
|
|
import com.bnyer.file.config.MinioConfig; |
|
|
import com.bnyer.file.config.MinioConfig; |
|
|
import com.bnyer.file.utils.ImgUtil; |
|
|
import com.bnyer.file.utils.ImgUtil; |
|
|
|
|
|
import io.minio.ObjectStat; |
|
|
import net.coobird.thumbnailator.Thumbnails; |
|
|
import net.coobird.thumbnailator.Thumbnails; |
|
|
|
|
|
import org.apache.commons.compress.utils.IOUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
@ -11,8 +13,10 @@ import com.bnyer.file.utils.FileUploadUtils; |
|
|
import io.minio.MinioClient; |
|
|
import io.minio.MinioClient; |
|
|
import io.minio.PutObjectArgs; |
|
|
import io.minio.PutObjectArgs; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.awt.image.BufferedImage; |
|
|
import java.awt.image.BufferedImage; |
|
|
import java.io.InputStream; |
|
|
import java.io.InputStream; |
|
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Minio 文件存储 |
|
|
* Minio 文件存储 |
|
|
@ -69,4 +73,20 @@ public class MinioSysFileServiceImpl implements MinioService |
|
|
client.putObject(args); |
|
|
client.putObject(args); |
|
|
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + multipartFile.getName(); |
|
|
return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + multipartFile.getName(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void download(String fileName, HttpServletResponse response) { |
|
|
|
|
|
// 获取对象的元数据
|
|
|
|
|
|
try{ |
|
|
|
|
|
ObjectStat stat = client.statObject(minioConfig.getBucketName(), fileName); |
|
|
|
|
|
response.setContentType(stat.contentType()); |
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
|
|
|
|
|
InputStream is = client.getObject(minioConfig.getBucketName(), fileName); |
|
|
|
|
|
IOUtils.copy(is, response.getOutputStream()); |
|
|
|
|
|
is.close(); |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|