2

I am uploading objects to amazon s3 using AWS iOS SDK in Iphone, sometime error occurs and some of the objects are uploaded, remaining are not uploaded. I have created bucket and inside bucket i have created folder in which i have store my objects. I want to delete folder and all its object. Can anyone help me?

sharmaravi
  • 137
  • 3
  • 13

1 Answers1

3

First of all, there is not such thing as "folders" in S3. Most S3 clients (including the AWS web console) show them as folders only for convenience (grouping stuff), but in fact, what you see as a "folder name" is merely a prefix.

Being that said, my suggestion to you is using the listObjectsInBucket API call, passing in your "folder name" as prefix in the S3ListObjectsRequest parameter.
When you have obtained all the keys (file names including prefix) matching that prefix, use the deleteObjects API call, passing in the keys in S3ListObjectsRequest parameter.

For more details on folder/prefix and deleting stuff, please see these related links:
Delete files, directories and buckets in amazon s3 java
Thread on AWS forum regarding this subject

Community
  • 1
  • 1
Viccari
  • 9,029
  • 4
  • 43
  • 77
  • Would this still leave an empty "folder" on S3? I can create an empty "folder" in the S3 console. I understand the concept that this is just a prefix but it does exist independently of having files inside of it. – Alex Rablau Jun 19 '18 at 14:02
  • Just gave it a quick test using the AWS CLI and yes, it will leave the prefix with no real key under it (the CLI shows it with a `PRE` by the name, showing it is a prefix). Simply calling the `deleteObjects` API, passing the prefix (ending with a slash) as the key removes the empty folder. In the CLI, that would be the `rm` command. – Viccari Jun 20 '18 at 00:12