use of com.amazonaws.services.s3.model.DeleteObjectRequest in project FP-PSP-SERVER by FundacionParaguaya.
the class ImageUploadServiceImpl method deleteImage.
@Override
public void deleteImage(String logoUrl, String imageDirectory) {
if (logoUrl == null) {
return;
}
try {
String strRegion = applicationProperties.getAws().getStrRegion();
Regions region = Regions.valueOf(strRegion);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(region).build();
String bucketName = applicationProperties.getAws().getBucketName();
String fileName = logoUrl.substring(logoUrl.lastIndexOf('/') + 1);
String keyName = imageDirectory + fileName;
s3Client.deleteObject(new DeleteObjectRequest(bucketName, keyName));
} catch (SdkClientException sdkClientExc) {
LOG.error(sdkClientExc.getMessage(), sdkClientExc);
throw new AWSS3RuntimeException(sdkClientExc);
}
}
use of com.amazonaws.services.s3.model.DeleteObjectRequest in project dataverse by IQSS.
the class S3AccessIO method deleteAuxObject.
@Override
public void deleteAuxObject(String auxItemTag) throws IOException {
if (!this.canWrite()) {
open(DataAccessOption.WRITE_ACCESS);
}
String destinationKey = getDestinationKey(auxItemTag);
try {
DeleteObjectRequest dor = new DeleteObjectRequest(bucketName, destinationKey);
s3.deleteObject(dor);
} catch (AmazonClientException ase) {
logger.warning("S3AccessIO: Unable to delete object " + ase.getMessage());
}
}
use of com.amazonaws.services.s3.model.DeleteObjectRequest in project dataverse by IQSS.
the class S3AccessIO method delete.
@Override
public void delete() throws IOException {
open();
if (key == null) {
throw new IOException("Failed to delete the object because the key was null");
}
try {
DeleteObjectRequest deleteObjRequest = new DeleteObjectRequest(bucketName, key);
s3.deleteObject(deleteObjRequest);
} catch (AmazonClientException ase) {
logger.warning("Caught an AmazonServiceException in S3AccessIO.delete(): " + ase.getMessage());
throw new IOException("Failed to delete object" + dvObject.getId());
}
}
Aggregations