Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

OSS Delete Bucket Objects (Alibaba Cloud)

See more Alibaba Cloud OSS Examples

Demonstrates how to delete objects in a bucket.

The Chilkat S3 functions in the HTTP class are compatible with Alibaba Cloud's OSS service.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringTable;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

        // Insert your AccessKey ID here:
        http.setAwsAccessKey("access-key");

        // Insert your AccessKey Secret here:
        http.setAwsSecretKey("secret-key");

        // To delete objects from a bucket located in a different region, use the domain for that region, such as "oss-cn-hangzhou.aliyuncs.com     "
        // See Alibaba Object Storage Service Regions and Endpoints
        http.setAwsEndpoint("oss-us-east-1.aliyuncs.com");

        String bucketName = "chilkat";

        String objectName1 = "seahorse.jpg";
        String objectName2 = "orchard.json";

        StringTable st = new StringTable();
        st.append(objectName1);
        st.append(objectName2);

        JsonObject jsonResp = new JsonObject();
        try {
            http.s3DeleteObjects(bucketName, st, jsonResp);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Response status code = " + http.getLastStatus());

        // Display the JSON response.
        jsonResp.setEmitCompact(false);
        System.out.println(jsonResp.emit());
    }
}