spring mvc rest apiを使用してaws-s3バケットにファイルをアップロードしようとしています。ここではここファイルがs3バケットにアップロードされていません
[default]
aws_access_key_id = Access key id
aws_secret_access_key = secret access key
S3バケットにアクセスするための私の資格情報の形式は、私のJavaコードがあるさ:
@RestController
public class UploadController {
private static String bucketName= "mp4-upload-1";
private static String keyName= "secret access key";
public static final Logger logger=LogManager.getLogger(UploadController.class);
@RequestMapping(value="/uploadVideo", method = RequestMethod.POST, consumes=MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<String> uploadVideo(@RequestParam("file") MultipartFile file) throws IOException {
AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
try {
System.out.println("Uploading a new object to S3 from a file\n");
InputStream is=file.getInputStream();
s3client.putObject(new PutObjectRequest(bucketName, keyName,is,new ObjectMetadata()).withCannedAcl(CannedAccessControlList.PublicRead));
} catch (AmazonServiceException ase) {
System.out.println("Caught an AmazonServiceException, which " +
"means your request made it " +
"to Amazon S3, but was rejected with an error response" +
" for some reason.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
System.out.println("Caught an AmazonClientException, which " +
"means the client encountered " +
"an internal error while trying to " +
"communicate with S3, " +
"such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
}
return new ResponseEntity<>(HttpStatus.OK);
}
}
問題は、私はすべてのエラーを取得していないのですが、ファイルをS3にアップロードされていないです-バケツ。私はここに何かを逃していますか事前に感謝します
本当の資格情報ですか?すぐに削除することをお勧めします。 – realharry
それを削除するだけではなく、そのキーを無効にしてください。通常、人々はAWSクレデンシャルを探してEC2インスタンスをたくさんスピンアップするカスタムスクリプトをいくつか持っています。 – Ian
ここから資格情報を削除し、新しい鍵を生成します(他の場所で共有しないでください)。したがって、資格情報を必要とせずに、依然として問題を検討することができます。 –