Java Code Examples for com.amazonaws.services.s3.AmazonS3.deleteObject()

The following are Jave code examples for showing how to use deleteObject() of the com.amazonaws.services.s3.AmazonS3 class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: dataset-lib   File: S3Provider.java   View Source Code Vote up 6 votes
public void remove(Object[] params) {
    AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
    try {
        s3client.deleteObject(new DeleteObjectRequest(bucketName, params[0].toString()));
    } 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());
    }

}
 
Example 2
Project: ooso   File: Commons.java   View Source Code Vote up 5 votes
public static void emptyBucketWithPrefix(String bucket, String prefix) {
    AmazonS3 s3Client = AmazonS3Provider.getS3Client();

    List<S3ObjectSummary> files = Commons.getBucketObjectSummaries(bucket, prefix);

    for (S3ObjectSummary object : files)
        s3Client.deleteObject(object.getBucketName(), object.getKey());
}
 
Example 3
Project: ats-framework   File: S3Operations.java   View Source Code Vote up 5 votes
/**
 * Delete object
 * @param object name/key of the object to be deleted
 */
@PublicAtsApi
public void deleteObject( String objectName ) {

    AmazonS3 s3Client = getClient();
    s3Client.deleteObject(bucketName, objectName);
    LOG.info("Deleted object '" + objectName + "' from bucket '" + bucketName + "'");
}
 
Example 4
Project: ats-framework   File: S3Operations.java   View Source Code Vote up 5 votes
/**
 * Move or rename file from one bucket to another
 *
 * @param fromBucket the bucket name, where the file is currently located
 * @param toBucket the bucket name, where the file will be moved
 * @param file the name of the file, that will be moved
 */
@PublicAtsApi
public void move( String fromBucket, String toBucket, String file ) {

    AmazonS3 s3Client = getClient();

    try {
        s3Client.copyObject(fromBucket, file, toBucket, file);
        s3Client.deleteObject(fromBucket, file);
    } catch (Exception e) {
        handleExeption(e, "S3 object move error");
    }
}
 
Example 5
Project: rxjava2-aws   File: Sqs.java   View Source Code Vote up 5 votes
public static String sendToQueueUsingS3(AmazonSQS sqs, String queueUrl, AmazonS3 s3, String bucketName,
        Map<String, String> headers, byte[] message, Callable<String> s3IdFactory) {
    Preconditions.checkNotNull(sqs);
    Preconditions.checkNotNull(s3);
    Preconditions.checkNotNull(queueUrl);
    Preconditions.checkNotNull(bucketName);
    Preconditions.checkNotNull(message);
    String s3Id;
    try {
        s3Id = s3IdFactory.call();
    } catch (final Exception e1) {
        throw new RuntimeException(e1);
    }
    final ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(message.length);
    for (final Entry<String, String> header : headers.entrySet()) {
        metadata.setHeader(header.getKey(), header.getValue());
    }
    s3.putObject(bucketName, s3Id, new ByteArrayInputStream(message), metadata);
    try {
        sqs.sendMessage(queueUrl, s3Id);
    } catch (final RuntimeException e) {
        try {
            s3.deleteObject(bucketName, s3Id);
            throw e;
        } catch (final RuntimeException e2) {
            throw new io.reactivex.exceptions.CompositeException(e, e2);
        }
    }
    return s3Id;
}
 
Example 6
Project: smart-security-camera   File: S3ArchiveImageHandler.java   View Source Code Vote up 5 votes
@Override
public Parameters handleRequest(Parameters parameters, Context context) {

    context.getLogger().log("Input Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");

    // The archive location of the snapshot will be decided by the alert
    // flag
    String newFilename;
    if (parameters.getSendAlert()) {
        newFilename = parameters.getS3Key().replace("upload/", "archive/alerts/");
    } else {
        newFilename = parameters.getS3Key().replace("upload/", "archive/falsepositives/");
    }

    // Ensure that the first two hyphens are used to create sub-directories
    // in the file path
    newFilename = newFilename.replaceFirst("-", "/");
    newFilename = newFilename.replaceFirst("-", "/");

    // Using the S3 client, first copy the file to the archive, and then
    // delete the original
    AmazonS3 client = AmazonS3ClientBuilder.defaultClient();
    CopyObjectRequest copyObjectRequest = new CopyObjectRequest(parameters.getS3Bucket(), parameters.getS3Key(), parameters.getS3Bucket(), newFilename);
    client.copyObject(copyObjectRequest);
    DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(parameters.getS3Bucket(), parameters.getS3Key());
    client.deleteObject(deleteObjectRequest);

    // Place the new location in the parameters
    parameters.setS3ArchivedKey(newFilename);

    context.getLogger().log("Output Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");

    return parameters;
}