| | |
| | | package com.dji.sample.component.oss.service.impl; |
| | | |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.component.oss.model.OssConfiguration; |
| | | import com.dji.sample.component.oss.model.enums.OssTypeEnum; |
| | | import com.dji.sample.component.oss.service.IOssService; |
| | |
| | | public class MinIOServiceImpl implements IOssService { |
| | | |
| | | private MinioClient client; |
| | | |
| | | |
| | | @Override |
| | | public String getOssType() { |
| | | return OssTypeEnum.MINIO.getType(); |
| | |
| | | @Override |
| | | public CredentialsDTO getCredentials() { |
| | | try { |
| | | AssumeRoleProvider provider = new AssumeRoleProvider(OssConfiguration.endpoint, OssConfiguration.accessKey, |
| | | AssumeRoleProvider provider = new AssumeRoleProvider(OssConfiguration.externalEndpoint, OssConfiguration.accessKey, |
| | | OssConfiguration.secretKey, Math.toIntExact(OssConfiguration.expire), |
| | | null, OssConfiguration.region, null, null, null, null); |
| | | return new CredentialsDTO(provider.fetch(), OssConfiguration.expire); |
| | |
| | | } catch (ErrorResponseException | InsufficientDataException | InternalException | |
| | | InvalidKeyException | InvalidResponseException | IOException | |
| | | NoSuchAlgorithmException | XmlParserException | ServerException e) { |
| | | throw new RuntimeException("The file does not exist on the OssConfiguration."); |
| | | throw new RuntimeException("OssConfiguration上不存在该文件."); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void putObject(String bucket, String objectKey, InputStream input) { |
| | | public String putObject(String bucket, String objectKey, InputStream input) { |
| | | try { |
| | | client.statObject(StatObjectArgs.builder().bucket(bucket).object(objectKey).build()); |
| | | throw new RuntimeException("The filename already exists."); |
| | | return "航线名重复"; |
| | | } catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) { |
| | | log.info("The file does not exist, start uploading."); |
| | | log.info("文件不存在,开始上传。"); |
| | | try { |
| | | ObjectWriteResponse response = client.putObject( |
| | | PutObjectArgs.builder().bucket(bucket).object(objectKey).stream(input, input.available(), 0).build()); |
| | |
| | | ex.printStackTrace(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public void createClient() { |