| | |
| | | import com.example.jz.config.MinIOConfig; |
| | | import com.example.jz.exception.BusinessException; |
| | | import com.example.jz.service.MinIOService; |
| | | import io.minio.GetPresignedObjectUrlArgs; |
| | | import io.minio.MinioClient; |
| | | import io.minio.PutObjectOptions; |
| | | import io.minio.UploadObjectArgs; |
| | | import io.minio.errors.*; |
| | | import io.minio.http.Method; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.security.InvalidKeyException; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @Service |
| | | public class MinIOServiceImpl implements MinIOService { |
| | |
| | | @Autowired |
| | | MinIOConfig minIOConfig; |
| | | |
| | | @Value("${minio.url}") |
| | | String url; |
| | | |
| | | @Value("${minio.bucketName}") |
| | | String bucketName; |
| | | |
| | | private static final String PATH = "http://221.237.182.28:19000/"; |
| | | |
| | | |
| | | @Override |
| | | public String getPreviewFileUrl(String fileName) { |
| | | String res = null; |
| | | try { |
| | | res = minioClient.getPresignedObjectUrl( |
| | | GetPresignedObjectUrlArgs.builder() |
| | | .method(Method.GET) |
| | | .bucket(minIOConfig.getBucketName()) |
| | | .object(fileName) |
| | | .build()); |
| | | return PATH + bucketName + '/' + fileName; |
| | | } catch (Exception e) { |
| | | throw new BusinessException("获取文件预览地址失败"); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | @Override |