Amazon 亚马逊 注释
This commit is contained in:
parent
464f4ba7c8
commit
74edf421d4
46
pom.xml
46
pom.xml
|
|
@ -23,7 +23,7 @@
|
|||
<mssql.version>4.0</mssql.version>
|
||||
<oracle.version>11.2.0.3</oracle.version>
|
||||
<druid.version>1.1.13</druid.version>
|
||||
<quartz.version>2.3.0</quartz.version>
|
||||
<!-- <quartz.version>2.3.0</quartz.version>-->
|
||||
<commons.lang.version>2.6</commons.lang.version>
|
||||
<commons.fileupload.version>1.2.2</commons.fileupload.version>
|
||||
<commons.io.version>2.5</commons.io.version>
|
||||
|
|
@ -85,17 +85,17 @@
|
|||
<artifactId>guava</artifactId>
|
||||
<version>19.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk</artifactId>
|
||||
<version>1.11.274</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>aws-java-sdk-simpleworkflow</artifactId>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.amazonaws</groupId>-->
|
||||
<!-- <artifactId>aws-java-sdk</artifactId>-->
|
||||
<!-- <version>1.11.274</version>-->
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <artifactId>aws-java-sdk-simpleworkflow</artifactId>-->
|
||||
<!-- <groupId>com.amazonaws</groupId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>cn.afterturn</groupId>
|
||||
<artifactId>easypoi-spring-boot-starter</artifactId>
|
||||
|
|
@ -325,17 +325,17 @@
|
|||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>${druid.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
<artifactId>quartz</artifactId>
|
||||
<version>${quartz.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.mchange</groupId>
|
||||
<artifactId>c3p0</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.quartz-scheduler</groupId>-->
|
||||
<!-- <artifactId>quartz</artifactId>-->
|
||||
<!-- <version>${quartz.version}</version>-->
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>com.mchange</groupId>-->
|
||||
<!-- <artifactId>c3p0</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.sqx.modules.app.entity;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.amazonaws.services.dynamodbv2.xspec.L;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
//import com.amazonaws.services.dynamodbv2.xspec.L;
|
||||
//import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
|
@ -12,7 +12,7 @@ import io.swagger.annotations.ApiModel;
|
|||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
//import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ package com.sqx.modules.file;
|
|||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.model.CannedAccessControlList;
|
||||
import com.amazonaws.services.s3.model.ObjectMetadata;
|
||||
//import com.amazonaws.services.s3.AmazonS3;
|
||||
//import com.amazonaws.services.s3.model.CannedAccessControlList;
|
||||
//import com.amazonaws.services.s3.model.ObjectMetadata;
|
||||
import com.qcloud.cos.COSClient;
|
||||
import com.qcloud.cos.ClientConfig;
|
||||
import com.qcloud.cos.auth.BasicCOSCredentials;
|
||||
|
|
@ -56,12 +56,14 @@ public class AliFileUploadController {
|
|||
|
||||
|
||||
private final CommonInfoService commonRepository;
|
||||
private AmazonS3 amazonS3;
|
||||
// private AmazonS3 amazonS3;
|
||||
|
||||
@Autowired
|
||||
public AliFileUploadController(CommonInfoService commonRepository, AmazonS3 amazonS3) {
|
||||
public AliFileUploadController(CommonInfoService commonRepository
|
||||
// , AmazonS3 amazonS3
|
||||
) {
|
||||
this.commonRepository = commonRepository;
|
||||
this.amazonS3 = amazonS3;
|
||||
// this.amazonS3 = amazonS3;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/getCredentials")
|
||||
|
|
@ -164,24 +166,24 @@ public class AliFileUploadController {
|
|||
cosclient.shutdown();
|
||||
}
|
||||
}else if("3".equals(value)){
|
||||
String suffix = file.getOriginalFilename().substring(Objects.requireNonNull(file.getOriginalFilename()).lastIndexOf("."));
|
||||
// 上传文件流。
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream =new ByteArrayInputStream(file.getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String completePath=getPath(suffix);
|
||||
String bucket=commonRepository.findOne(810).getValue();
|
||||
com.amazonaws.services.s3.model.PutObjectRequest putObjectRequest = new com.amazonaws.services.s3.model.PutObjectRequest(bucket, completePath, inputStream, new ObjectMetadata());
|
||||
|
||||
putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
|
||||
|
||||
com.amazonaws.services.s3.model.PutObjectResult putObjectResult = amazonS3.putObject(putObjectRequest);
|
||||
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
return Result.success().put("data",commonRepository.findOne(811).getValue()+"/"+completePath);
|
||||
// String suffix = file.getOriginalFilename().substring(Objects.requireNonNull(file.getOriginalFilename()).lastIndexOf("."));
|
||||
// // 上传文件流。
|
||||
// InputStream inputStream = null;
|
||||
// try {
|
||||
// inputStream =new ByteArrayInputStream(file.getBytes());
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// String completePath=getPath(suffix);
|
||||
// String bucket=commonRepository.findOne(810).getValue();
|
||||
// com.amazonaws.services.s3.model.PutObjectRequest putObjectRequest = new com.amazonaws.services.s3.model.PutObjectRequest(bucket, completePath, inputStream, new ObjectMetadata());
|
||||
//
|
||||
// putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
|
||||
//
|
||||
// com.amazonaws.services.s3.model.PutObjectResult putObjectResult = amazonS3.putObject(putObjectRequest);
|
||||
//
|
||||
// IOUtils.closeQuietly(inputStream);
|
||||
// return Result.success().put("data",commonRepository.findOne(811).getValue()+"/"+completePath);
|
||||
}else if("4".equals(value)){
|
||||
String endpoint = "tos-cn-beijing.volces.com";
|
||||
String region = "cn-beijing";
|
||||
|
|
@ -301,24 +303,24 @@ public class AliFileUploadController {
|
|||
cosclient.shutdown();
|
||||
}
|
||||
}else if("3".equals(value)){
|
||||
String suffix = file.getOriginalFilename().substring(Objects.requireNonNull(file.getOriginalFilename()).lastIndexOf("."));
|
||||
// 上传文件流。
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream =new ByteArrayInputStream(file.getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String completePath=getPath(suffix);
|
||||
String bucket=commonRepository.findOne(810).getValue();
|
||||
com.amazonaws.services.s3.model.PutObjectRequest putObjectRequest = new com.amazonaws.services.s3.model.PutObjectRequest(bucket, completePath, inputStream, new ObjectMetadata());
|
||||
|
||||
putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
|
||||
|
||||
com.amazonaws.services.s3.model.PutObjectResult putObjectResult = amazonS3.putObject(putObjectRequest);
|
||||
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
return commonRepository.findOne(811).getValue()+"/"+completePath;
|
||||
// String suffix = file.getOriginalFilename().substring(Objects.requireNonNull(file.getOriginalFilename()).lastIndexOf("."));
|
||||
// // 上传文件流。
|
||||
// InputStream inputStream = null;
|
||||
// try {
|
||||
// inputStream =new ByteArrayInputStream(file.getBytes());
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// String completePath=getPath(suffix);
|
||||
// String bucket=commonRepository.findOne(810).getValue();
|
||||
// com.amazonaws.services.s3.model.PutObjectRequest putObjectRequest = new com.amazonaws.services.s3.model.PutObjectRequest(bucket, completePath, inputStream, new ObjectMetadata());
|
||||
//
|
||||
// putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
|
||||
//
|
||||
// com.amazonaws.services.s3.model.PutObjectResult putObjectResult = amazonS3.putObject(putObjectRequest);
|
||||
//
|
||||
// IOUtils.closeQuietly(inputStream);
|
||||
// return commonRepository.findOne(811).getValue()+"/"+completePath;
|
||||
}else if("4".equals(value)){
|
||||
String endpoint = "tos-cn-beijing.volces.com";
|
||||
String region = "cn-beijing";
|
||||
|
|
|
|||
|
|
@ -1,91 +1,91 @@
|
|||
package com.sqx.modules.file;
|
||||
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.model.*;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class S3Service {
|
||||
|
||||
@Autowired
|
||||
private AmazonS3 amazonS3;
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
|
||||
private PutObjectResult upload(String filePath, String uploadKey) throws FileNotFoundException {
|
||||
return upload(new FileInputStream(filePath), uploadKey);
|
||||
}
|
||||
|
||||
private PutObjectResult upload(InputStream inputStream, String uploadKey) {
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(commonInfoService.findOne(810).getValue(), uploadKey, inputStream, new ObjectMetadata());
|
||||
|
||||
putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
|
||||
|
||||
PutObjectResult putObjectResult = amazonS3.putObject(putObjectRequest);
|
||||
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
|
||||
return putObjectResult;
|
||||
}
|
||||
|
||||
public List<PutObjectResult> upload(MultipartFile[] multipartFiles) {
|
||||
List<PutObjectResult> putObjectResults = new ArrayList<>();
|
||||
|
||||
Arrays.stream(multipartFiles)
|
||||
.filter(multipartFile -> !StringUtils.isEmpty(multipartFile.getOriginalFilename()))
|
||||
.forEach(multipartFile -> {
|
||||
try {
|
||||
putObjectResults.add(upload(multipartFile.getInputStream(), multipartFile.getOriginalFilename()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
return putObjectResults;
|
||||
}
|
||||
|
||||
public ResponseEntity<byte[]> download(String key) throws IOException {
|
||||
GetObjectRequest getObjectRequest = new GetObjectRequest(commonInfoService.findOne(810).getValue(), key);
|
||||
|
||||
S3Object s3Object = amazonS3.getObject(getObjectRequest);
|
||||
|
||||
S3ObjectInputStream objectInputStream = s3Object.getObjectContent();
|
||||
|
||||
byte[] bytes = IOUtils.toByteArray(objectInputStream);
|
||||
|
||||
String fileName = URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20");
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
httpHeaders.setContentLength(bytes.length);
|
||||
httpHeaders.setContentDispositionFormData("attachment", fileName);
|
||||
|
||||
return new ResponseEntity<>(bytes, httpHeaders, HttpStatus.OK);
|
||||
}
|
||||
|
||||
public List<S3ObjectSummary> list() {
|
||||
ObjectListing objectListing = amazonS3.listObjects(new ListObjectsRequest().withBucketName(commonInfoService.findOne(810).getValue()));
|
||||
|
||||
List<S3ObjectSummary> s3ObjectSummaries = objectListing.getObjectSummaries();
|
||||
|
||||
return s3ObjectSummaries;
|
||||
}
|
||||
}
|
||||
//package com.sqx.modules.file;
|
||||
//
|
||||
//import com.amazonaws.services.s3.AmazonS3;
|
||||
//import com.amazonaws.services.s3.model.*;
|
||||
//import com.sqx.modules.common.service.CommonInfoService;
|
||||
//import org.apache.commons.io.IOUtils;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.http.HttpHeaders;
|
||||
//import org.springframework.http.HttpStatus;
|
||||
//import org.springframework.http.MediaType;
|
||||
//import org.springframework.http.ResponseEntity;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.util.StringUtils;
|
||||
//import org.springframework.web.multipart.MultipartFile;
|
||||
//
|
||||
//import java.io.FileInputStream;
|
||||
//import java.io.FileNotFoundException;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStream;
|
||||
//import java.net.URLEncoder;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Arrays;
|
||||
//import java.util.List;
|
||||
//
|
||||
//@Service
|
||||
//public class S3Service {
|
||||
//
|
||||
// @Autowired
|
||||
// private AmazonS3 amazonS3;
|
||||
// @Autowired
|
||||
// private CommonInfoService commonInfoService;
|
||||
//
|
||||
// private PutObjectResult upload(String filePath, String uploadKey) throws FileNotFoundException {
|
||||
// return upload(new FileInputStream(filePath), uploadKey);
|
||||
// }
|
||||
//
|
||||
// private PutObjectResult upload(InputStream inputStream, String uploadKey) {
|
||||
// PutObjectRequest putObjectRequest = new PutObjectRequest(commonInfoService.findOne(810).getValue(), uploadKey, inputStream, new ObjectMetadata());
|
||||
//
|
||||
// putObjectRequest.setCannedAcl(CannedAccessControlList.PublicRead);
|
||||
//
|
||||
// PutObjectResult putObjectResult = amazonS3.putObject(putObjectRequest);
|
||||
//
|
||||
// IOUtils.closeQuietly(inputStream);
|
||||
//
|
||||
// return putObjectResult;
|
||||
// }
|
||||
//
|
||||
// public List<PutObjectResult> upload(MultipartFile[] multipartFiles) {
|
||||
// List<PutObjectResult> putObjectResults = new ArrayList<>();
|
||||
//
|
||||
// Arrays.stream(multipartFiles)
|
||||
// .filter(multipartFile -> !StringUtils.isEmpty(multipartFile.getOriginalFilename()))
|
||||
// .forEach(multipartFile -> {
|
||||
// try {
|
||||
// putObjectResults.add(upload(multipartFile.getInputStream(), multipartFile.getOriginalFilename()));
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// return putObjectResults;
|
||||
// }
|
||||
//
|
||||
// public ResponseEntity<byte[]> download(String key) throws IOException {
|
||||
// GetObjectRequest getObjectRequest = new GetObjectRequest(commonInfoService.findOne(810).getValue(), key);
|
||||
//
|
||||
// S3Object s3Object = amazonS3.getObject(getObjectRequest);
|
||||
//
|
||||
// S3ObjectInputStream objectInputStream = s3Object.getObjectContent();
|
||||
//
|
||||
// byte[] bytes = IOUtils.toByteArray(objectInputStream);
|
||||
//
|
||||
// String fileName = URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20");
|
||||
//
|
||||
// HttpHeaders httpHeaders = new HttpHeaders();
|
||||
// httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
// httpHeaders.setContentLength(bytes.length);
|
||||
// httpHeaders.setContentDispositionFormData("attachment", fileName);
|
||||
//
|
||||
// return new ResponseEntity<>(bytes, httpHeaders, HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
// public List<S3ObjectSummary> list() {
|
||||
// ObjectListing objectListing = amazonS3.listObjects(new ListObjectsRequest().withBucketName(commonInfoService.findOne(810).getValue()));
|
||||
//
|
||||
// List<S3ObjectSummary> s3ObjectSummaries = objectListing.getObjectSummaries();
|
||||
//
|
||||
// return s3ObjectSummaries;
|
||||
// }
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,34 @@
|
|||
package com.sqx.modules.file.config;
|
||||
|
||||
import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Configuration
|
||||
@Component
|
||||
public class AWSConfiguration {
|
||||
|
||||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
|
||||
@Bean
|
||||
public BasicAWSCredentials basicAWSCredentials() {
|
||||
return new BasicAWSCredentials(commonInfoService.findOne(807).getValue(), commonInfoService.findOne(808).getValue());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AmazonS3 amazonS3Client(AWSCredentials awsCredentials) {
|
||||
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
|
||||
builder.withCredentials(new AWSStaticCredentialsProvider(awsCredentials));
|
||||
builder.setRegion(commonInfoService.findOne(809).getValue());
|
||||
AmazonS3 amazonS3 = builder.build();
|
||||
return amazonS3;
|
||||
}
|
||||
}
|
||||
//package com.sqx.modules.file.config;
|
||||
//
|
||||
//import com.amazonaws.auth.AWSCredentials;
|
||||
//import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
//import com.amazonaws.auth.BasicAWSCredentials;
|
||||
//import com.amazonaws.services.s3.AmazonS3;
|
||||
//import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
//import com.sqx.modules.common.service.CommonInfoService;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//@Configuration
|
||||
//@Component
|
||||
//public class AWSConfiguration {
|
||||
//
|
||||
// @Autowired
|
||||
// private CommonInfoService commonInfoService;
|
||||
//
|
||||
// @Bean
|
||||
// public BasicAWSCredentials basicAWSCredentials() {
|
||||
// return new BasicAWSCredentials(commonInfoService.findOne(807).getValue(), commonInfoService.findOne(808).getValue());
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public AmazonS3 amazonS3Client(AWSCredentials awsCredentials) {
|
||||
// AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
|
||||
// builder.withCredentials(new AWSStaticCredentialsProvider(awsCredentials));
|
||||
// builder.setRegion(commonInfoService.findOne(809).getValue());
|
||||
// AmazonS3 amazonS3 = builder.build();
|
||||
// return amazonS3;
|
||||
// }
|
||||
//}
|
||||
|
|
|
|||
Loading…
Reference in New Issue