Skip to content

Latest commit

 

History

History
49 lines (39 loc) · 1.49 KB

DeleteObject.md

File metadata and controls

49 lines (39 loc) · 1.49 KB

DeleteObject Example

Code Snippet

Initialize the Bucket service with accesskeyid and secretaccesskey

EnvContext env = new EnvContext(accessKey,accessSecret);
String zoneKey = "pek3a";
String bucketName = "testBucketName";
Bucket bucket = new Bucket(env, zoneKey, bucketName);

then you can delete objects

    /**
     * Delete Object
     *
     * @param bucket    bucket
     * @param objectKey looks like this: "folder/fileName".<br/>
     *                  If objectKey = "fileName", means the object is in the bucket's root folder.
     */
    private void deleteObject(Bucket bucket, String objectKey) {
        try {
            Bucket.DeleteObjectOutput output = bucket.deleteObject(objectKey);
            if (output.getStatueCode() == 204) {
                // Deleted
                System.out.println("Delete Object: Deleted. ");
                System.out.println("Delete Object: Object key = " + objectKey);
            } else {
                // Failed
                System.out.println("Failed to delete " + objectKey);
                System.out.println("StatueCode = " + output.getStatueCode());
                System.out.println("Message = " + output.getMessage());
                System.out.println("RequestId = " + output.getRequestId());
                System.out.println("Code = " + output.getCode());
                System.out.println("Url = " + output.getUrl());
            }
        } catch (QSException e) {
            e.printStackTrace();
        }
    }