Search in sources :

Example 6 with DeleteObjectRequest

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);
    }
}
Also used : DeleteObjectRequest(com.amazonaws.services.s3.model.DeleteObjectRequest) AmazonS3(com.amazonaws.services.s3.AmazonS3) SdkClientException(com.amazonaws.SdkClientException) AWSS3RuntimeException(py.org.fundacionparaguaya.pspserver.common.exceptions.AWSS3RuntimeException) Regions(com.amazonaws.regions.Regions)

Example 7 with DeleteObjectRequest

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());
    }
}
Also used : DeleteObjectRequest(com.amazonaws.services.s3.model.DeleteObjectRequest) AmazonClientException(com.amazonaws.AmazonClientException)

Example 8 with DeleteObjectRequest

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());
    }
}
Also used : DeleteObjectRequest(com.amazonaws.services.s3.model.DeleteObjectRequest) AmazonClientException(com.amazonaws.AmazonClientException) IOException(java.io.IOException)

Aggregations

DeleteObjectRequest (com.amazonaws.services.s3.model.DeleteObjectRequest)8 AmazonServiceException (com.amazonaws.AmazonServiceException)3 DeleteVersionRequest (com.amazonaws.services.s3.model.DeleteVersionRequest)3 IOException (java.io.IOException)3 AmazonClientException (com.amazonaws.AmazonClientException)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 InterruptedIOException (java.io.InterruptedIOException)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 SdkClientException (com.amazonaws.SdkClientException)1 Regions (com.amazonaws.regions.Regions)1 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1 AWSS3RuntimeException (py.org.fundacionparaguaya.pspserver.common.exceptions.AWSS3RuntimeException)1