|
|
@@ -13,13 +13,11 @@ import com.amazonaws.services.s3.model.ObjectMetadata; |
|
|
import com.amazonaws.services.s3.model.PutObjectRequest; |
|
|
import com.amazonaws.services.s3.model.PutObjectRequest; |
|
|
import com.iformall.common.ResultData; |
|
|
import com.iformall.common.ResultData; |
|
|
import com.iformall.config.AwsProperty; |
|
|
import com.iformall.config.AwsProperty; |
|
|
import com.iformall.utils.AwsClient; |
|
|
|
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
@@ -27,7 +25,6 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream; |
|
|
import java.io.BufferedInputStream; |
|
|
import java.io.File; |
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.net.URL; |
|
|
import java.net.URL; |
|
|
@@ -45,6 +42,8 @@ public class UploadController extends BaseController { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private AwsProperty awsProperty; |
|
|
private AwsProperty awsProperty; |
|
|
|
|
|
|
|
|
|
|
|
private AmazonS3 s3 = null; |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
@Value("${fileUpload.path}") |
|
|
@Value("${fileUpload.path}") |
|
|
private String filePath; |
|
|
private String filePath; |
|
|
@@ -108,7 +107,22 @@ public class UploadController extends BaseController { |
|
|
private ResultData awsUpload(MultipartFile multiReq, ObjectMetadata metadata, String fileName) { |
|
|
private ResultData awsUpload(MultipartFile multiReq, ObjectMetadata metadata, String fileName) { |
|
|
ResultData data = new ResultData(); |
|
|
ResultData data = new ResultData(); |
|
|
try { |
|
|
try { |
|
|
AmazonS3 s3 = AwsClient.getInstance(); |
|
|
|
|
|
|
|
|
if(s3 == null) { |
|
|
|
|
|
s3 = AmazonS3ClientBuilder.standard() |
|
|
|
|
|
.withRegion(awsProperty.getClientRegion()) |
|
|
|
|
|
.withCredentials(new AWSCredentialsProvider() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public AWSCredentials getCredentials() { |
|
|
|
|
|
return new BasicAWSCredentials(awsProperty.getAccess(), awsProperty.getSecret()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void refresh() { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.build(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
s3.putObject( |
|
|
s3.putObject( |
|
|
new PutObjectRequest(awsProperty.getBucketName(), fileName, multiReq.getInputStream(), metadata) |
|
|
new PutObjectRequest(awsProperty.getBucketName(), fileName, multiReq.getInputStream(), metadata) |
|
|
|