How to use AWS iOS SDK to delete an object?

I am trying to delete a public image (the cannedACLproperty S3PutObjectRequestto download the image was [S3CannedACL publicRead]) loaded into the S3 bucket.

There is a class in theS3DeleteObjectRequest AWS SDK documentation , but there are no properties or initialization methods for this class .

Based on the sample code in other languages, there seems to be a property keyor bucketor initialization method that sets these properties, as it is in the iOS SDK S3PutObjectRequest, used to upload files to the bucket.

What's going on here? Is the SDK just incomplete? Is there a way to delete an object using the iOS AWS SDK?

+5
source share
3

, , ?

[s3Client deleteObjectWithKey:@"objectKey" withBucket:@"my-bucket"];
+6

iOS SDK S3 V2

AWSS3 *s3 = [AWSS3 defaultS3];
                AWSS3DeleteObjectRequest *deleteRequest = [AWSS3DeleteObjectRequest new];
                deleteRequest.bucket = S3BucketName;
                deleteRequest.key = climb.imageKey;
                [[[s3 deleteObject:deleteRequest] continueWithBlock:^id(BFTask *task) {
                    if(task.error != nil){
                        if(task.error.code != AWSS3TransferManagerErrorCancelled && task.error.code != AWSS3TransferManagerErrorPaused){
                            NSLog(@"%s Error: [%@]",__PRETTY_FUNCTION__, task.error);
                        }
                    }else{
                        // Completed logic here
                    }
                    return nil;
                }] waitUntilFinished];
Hide result

, : https://github.com/aws/aws-sdk-ios/blob/master/AWSS3Tests/AWSS3Tests.m

+8

The answer to Gillespie's art worked just fine for me.

However, I also found that you can achieve the same by setting the attributes keyand bucketthe request for the removal of S3 object:

S3DeleteObjectRequest *dor = [[S3DeleteObjectRequest alloc] init];
dor.key = AWS_OBJ_PATH;
dor.bucket = AWS_BUCKET;

[s3Client deleteObject:dor];
+1
source

All Articles