Erro gerado ao tentar salvar a primeira foto.
Segue o Código.
Erro genérico acontecendo
com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied;
@Configuration
public class AmazonConfiguration {
private static final String ACCESS_KEY = "['CHAVE DE ACESSO'];
private static final String SECRET_KEY = "['CHAVE SECRETA']";
private static final String REGION = "us-east-1";
@Bean
public BasicAWSCredentials basicAWSCredentials() {
return new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
}
@Bean
public AmazonS3 amazonS3() {
return AmazonS3ClientBuilder.standard().withRegion(REGION)
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials())).build();
}
}
@Component
public class FileSaver {
@Autowired
private AmazonS3 amazonS3;
private static final String BUCKET = "casadocodigo-marciogalvao";
public String write(MultipartFile file) {
try {
amazonS3.putObject(new PutObjectRequest(BUCKET,
file.getOriginalFilename(), file.getInputStream(), null)
.withCannedAcl(CannedAccessControlList.PublicRead));
return "http://s3.amazonaws.com/" + BUCKET + "/" + file.getOriginalFilename();
} catch (IllegalStateException | IOException e) {
throw new RuntimeException(e);
}
}
}