Hello, how do I record a resource that is inside a war structure, generated by the deploy of the java application, in the AW3 S3.
The method below works when the application is on the local server, but when I deploy through ElasticBEanastalk, the same application does not write.
public void loadFile(byte[] foto, String id, String url) {
try {
Path path = Paths.get(url + id + ".jpg");
Files.deleteIfExists(path);
InputStream initialStream = new ByteArrayInputStream(foto);
byte[] buffer = new byte[initialStream.available()];
initialStream.read(buffer);
File targetFile = new File(url + id + ".jpg");
OutputStream outStream = new FileOutputStream(targetFile);
outStream.write(buffer);
outStream.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println("Impressao do StackTrace do erro de envio de email: "+e.toString());
}
}
I discovered and tested the AmazonS3 api, shown below, which writes a file into a folder in the root of the bucket, but does not figure out how to write to a folder inside the war file.
public void loadFile(byte[] foto, String id, String url) {
try {
AWSCredentials credentials = new BasicAWSCredentials("AKIvJXEtttEIGOVDX3E6Q","a33aLafwtttttXyJTITEUJSTP6DCfruqTxabgI");
AmazonS3Client amazonS3Client = new AmazonS3Client(credentials);
AmazonS3 s3 = new AmazonS3Client(credentials);
s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.SA_EAST_1)
.withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
s3.putObject(new PutObjectRequest("elasticbeanstalk-sa-east-1-122554548526", id + ".jpg", new File(url + id + ".jpg")));
Thanks, if anyone has a suggestion to solve the problem.