| | |
| | | public class AliyunOssServiceImpl implements IOssService { |
| | | |
| | | private OSS ossClient; |
| | | |
| | | |
| | | @Override |
| | | public String getOssType() { |
| | | return OssTypeEnum.ALIYUN.getType(); |
| | |
| | | // First check if the object can be fetched. |
| | | boolean isExist = ossClient.doesObjectExist(bucket, objectKey); |
| | | if (!isExist) { |
| | | throw new OSSException("The object does not exist."); |
| | | throw new OSSException("对象不存在"); |
| | | } |
| | | |
| | | return ossClient.generatePresignedUrl(bucket, objectKey, |
| | |
| | | @Override |
| | | public void putObject(String bucket, String objectKey, InputStream input) { |
| | | if (ossClient.doesObjectExist(bucket, objectKey)) { |
| | | throw new RuntimeException("The filename already exists."); |
| | | throw new RuntimeException("文件已存在"); |
| | | } |
| | | PutObjectResult objectResult = ossClient.putObject(new PutObjectRequest(bucket, objectKey, input, new ObjectMetadata())); |
| | | log.info("Upload File: {}", objectResult.getETag()); |