Sample code for 30+ languages & platforms
Java

S3 Delete Multiple Objects

See more Amazon S3 Examples

Demonstrates how to delete multiple objects in a single HTTP request.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();

    // Insert your access key here:
    http.put_AwsAccessKey("ABQXXABC83ABCDEFVQXX");

    // Insert your secret key here:
    http.put_AwsSecretKey("XXXXYYYYabcdABCD12345678xxxxyyyyzzzz");

    String bucketName = "chilkattestbucket";

    String objectName1 = "starfish.jpg";
    // Delete a particular version of this object:
    String objectName2 = "conch.jpg; VersionId=\"3/L4kqtJlcpXroDTDmJ+rmSpXd3dIbrHY+MTRCxf3vjVBH40Nr8X8gdRQBpUMLUo\"";
    String objectName3 = "seaUrchin.jpg";

    CkStringTable st = new CkStringTable();
    st.Append(objectName1);
    st.Append(objectName2);
    st.Append(objectName3);

    CkHttpResponse resp = new CkHttpResponse();
    success = http.S3_DeleteObjects(bucketName,st,resp);
    if (success == false) {
        System.out.println(http.lastErrorText());
        return;
        }

    // Display the JSON response.
    System.out.println(resp.bodyStr());
  }
}