Nimblechapps Blog

This is the section where we get a chance to rant about latest happenings in the tech world. Keen to know our thoughts? Refer our blogs

Using Amazon S3 To Store, List and Remove Images from your iOS App

Using Amazon S3 To Store, List and Remove Images from your iOS App

Amazon Simple Storage Service (S3) provides secure, durable, highly scalable object storage in the cloud. Using the AWS Mobile SDK for iOS, you can directly access Amazon S3 from your mobile app.

With AWS object storage solutions like Amazon Simple Storage Service (Amazon S3) and Amazon Glacier, you manage your storage in one place with an easy-to-use application interface. You can use policies to optimize storage costs, tiering between different storage classes automatically. AWS makes storage easier to use to perform analysis, gain insights, and make better decisions faster.

Amazon S3 Benefits

Amazon S3 provides the most powerful object storage platform available in the cloud today.

1

Unmatched durability, reliability, & scalability.

2

Most comprehensive security & compliance capabilities.

3

Query in place.

4

Flexible management.

5

Most supported platform with the largest ecosystem.

6

Easy, flexible data transfer.


Warning: preg_match() expects parameter 2 to be string, array given in /home/savecont/public_html/nimblechapps.com/wp-content/plugins/js_composer/include/templates/shortcodes/vc_empty_space.php on line 10

Getting Started with AWS S3

Amazon Simple Storage Service (Amazon S3) is storage for the Internet. You can use Amazon S3 to store and retrieve any amount of data at any time, from anywhere on the web. You can accomplish these tasks using the AWS Management Console, which is a simple and intuitive web interface.  You can get the whole documentation from here – AWS s3

Before proceeding further please follow the documentation to create the s3 account and as well the bucket. Every object in Amazon S3 is stored in a bucket. Before you can store data in Amazon S3, you must create a bucket.

Let’s get started with integrating AWS SDK to iOS app and build a sample to:

1

Store images.

2

List images.

3

Remove images.

The AWS Mobile Android and iOS SDKs help you build high quality mobile apps quickly and easily. They provide easy access to a range of AWS services, including Amazon Cognito, AWS Lambda, Amazon S3, Amazon Kinesis, Amazon DynamoDB, Amazon Pinpoint and many more.

Please check set-up here how to configure the iOS app and do necessary configurations.  We need to configure “Add User DataStorage” to the iOS app we will be creating in the AWS mobile hub.

User Data Storage

Enable your app to store and retrieve user files from cloud storage with the permissions model that suits your purpose. Mobile Hub User Data Storage deploys and configures cloud storage buckets using Amazon Simple Storage Service (Amazon S3).

Follow the steps listed here to configure the data storage feature to the app. So now Update your app with the latest copy of the cloud configuration file that has to be downloaded after the user data storage has been configured.

Till here we are able to configure the required set-up for AWS SDK and as well setting-up the app in AWS mobile hub and using the cloud configuration file.

Let’s start working on the application to save, list and delete the images in the s3 bucket we had created in the above process.

Requirements

  • Xcode 7 and later
  • iOS 8 and later

1. Open Xcode and select a single view application and name it as you like. For the sample i use as s3sample.

2. There are three ways to import the AWS Mobile SDK for iOS into your project:

You should use one of these three ways to import the AWS Mobile SDK but not multiple. Importing the SDK in multiple ways loads duplicate copies of the SDK into the project and causes compiler errors.

3. Let’s use Carthage to set-up the SDK.

4. Install the latest version of Carthage, navigate to your project folder and create the Cartfile and add the following to your Cartfile that is created in your project:

github “aws/aws-sdk-ios”

5. Then run the following command:

$ carthage update  

6. Now open the project in Xcode, select your Target. Under General tab, find Embedded Binaries and then click ‘+’ button.

7. Click the Add Other… button, navigate to the AWS<#ServiceName#>.framework files that are listed under Carthage -> build -> iOS and select them. Do not check the Destination: Copy items if needed checkbox when prompted.

8. Under the Build Phases tab in your Target, click the + button on the top left and then select New Run Script Phase. Then setup the build phase as follows. Make sure this phase is below the Embed Frameworks phase.

[pastacode lang=”c” manual=”Shell%C2%A0%2Fbin%2Fsh%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0bash%C2%A0%22%24%7BBUILT_PRODUCTS_DIR%7D%2F%24%7BFRAMEWORKS_FOLDER_PATH%7D%2FAWSCore.framework%2Fstrip-frameworks.sh%22%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0Show%C2%A0environment%C2%A0variables%C2%A0in%C2%A0build%C2%A0log%3A%C2%A0Checked%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0Run%C2%A0script%C2%A0only%C2%A0when%C2%A0installing%3A%C2%A0Not%C2%A0checked%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0Input%C2%A0Files%3A%C2%A0Empty%C2%A0%C2%A0Output%C2%A0Files%3A%C2%A0Empty” message=”” highlight=”” provider=”manual”/]

9. Running the following command in your project directory with Carthage will automatically pickup the new changes if any in SDK.

$ carthage update  

10. Add the following imports to the classes that perform user data storage operations:

[pastacode lang=”cpp” manual=”import%C2%A0AWSCore%C2%A0%C2%A0%0Aimport%C2%A0AWSS3″ message=”” highlight=”” provider=”manual”/]

11. Add the following code to your AppDelegate to establish a run-time connection with AWS Mobile.

[pastacode lang=”cpp” manual=”import%C2%A0AWSMobileClient%C2%A0%C2%A0%0A%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0func%C2%A0application(_%C2%A0application%3A%C2%A0UIApplication%2C%C2%A0didFinishLaunchingWithOptions%C2%A0launchOptions%3A%C2%A0%5BUIApplicationLaunchOptionsKey%3A%C2%A0Any%5D%3F)%C2%A0-%3E%C2%A0Bool%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2F%C2%A0Override%C2%A0point%C2%A0for%C2%A0customization%C2%A0after%C2%A0application%C2%A0launch.%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0return%C2%A0AWSMobileClient.sharedInstance().interceptApplication(application%2C%C2%A0didFinishLaunchingWithOptions%3A%C2%A0launchOptions)%C2%A0%C2%A0%0A%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2F%C2%A0return%C2%A0true%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D” message=”” highlight=”” provider=”manual”/]

Let’s see how to upload an image file from device gallery to Amazon  S3 bucket

In XCode,  open the storyboard and in viewcontroller interface, add a button to open the device gallery, an imageview to show the selected image and as well another button to upload that image and set the respective actions and outlets for the buttons and imageview.

Write the following code.

To open the device gallery

[pastacode lang=”cpp” manual=”%40IBAction%C2%A0func%C2%A0selectImageFromGallery(_%C2%A0sender%3A%C2%A0UIButton)%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0imagePicker%C2%A0%3D%C2%A0UIImagePickerController()%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0imagePicker.delegate%C2%A0%3D%C2%A0self%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0imagePicker.allowsEditing%C2%A0%3D%C2%A0false%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0imagePicker.sourceType%C2%A0%3D%C2%A0.photoLibrary%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0present(imagePicker%2C%C2%A0animated%3A%C2%A0true%2C%C2%A0completion%3A%C2%A0nil)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D” message=”” highlight=”” provider=”manual”/]

To set the selected image to imageview using the imagepicker delegate method. Extend the image picker and navigation controller delegate to get the image picker delegate method assigned to the viewcontorller.

[pastacode lang=”cpp” manual=”func%C2%A0imagePickerController(_%C2%A0picker%3A%C2%A0UIImagePickerController%2C%C2%A0didFinishPickingMediaWithInfo%C2%A0info%3A%C2%A0%5BString%C2%A0%3A%C2%A0Any%5D)%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0if%C2%A0let%C2%A0pickedImage%C2%A0%3D%C2%A0info%5BUIImagePickerControllerOriginalImage%5D%C2%A0as%3F%C2%A0UIImage%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0selectedImageView.contentMode%C2%A0%3D%C2%A0.scaleAspectFit%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0selectedImageView.image%C2%A0%3D%C2%A0pickedImage%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0dismiss(animated%3A%C2%A0true%2C%C2%A0completion%3A%C2%A0nil)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D” message=”” highlight=”” provider=”manual”/]

And To upload the image to S3 bucket using the AWS Sdk methods.

For upload button Action

[pastacode lang=”cpp” manual=”%40IBAction%C2%A0func%C2%A0uploadImageToS3(_%C2%A0sender%3A%C2%A0UIButton)%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0uploadData(image%3A%C2%A0selectedImageView.image!)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%7D%C2%A0%C2%A0%0A%0Afunc%C2%A0getCurrentMillis()-%3EInt64%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0return%C2%A0Int64(Date().timeIntervalSince1970%C2%A0*%C2%A01000)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%0Afunc%C2%A0uploadData(image%3A%C2%A0UIImage)%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2F%C2%A0%C2%A0let%C2%A0img%C2%A0%3D%C2%A0UIImage(named%3A%C2%A0%22bob.jpg%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0data%3AData%C2%A0%3D%C2%A0UIImagePNGRepresentation(image)!%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0expression%C2%A0%3D%C2%A0AWSS3TransferUtilityUploadExpression()%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0expression.progressBlock%C2%A0%3D%C2%A0%7B(task%2C%C2%A0progress)%C2%A0in%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0DispatchQueue.main.async(execute%3A%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2F%C2%A0Do%C2%A0something%C2%A0e.g.%C2%A0Update%C2%A0a%C2%A0progress%C2%A0bar.%C2%A0%C2%A0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A0%C2%A0%C2%A0%C2%A0%2F%2F%C2%A0Do%C2%A0something%C2%A0e.g.%C2%A0Alert%C2%A0a%C2%A0user%C2%A0for%C2%A0transfer%C2%A0completion.%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2F%C2%A0On%C2%A0failed%C2%A0uploads%2C%C2%A0%60error%60%C2%A0contains%C2%A0the%C2%A0error%C2%A0object.%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0print(%22upload%C2%A0completed1%C2%A0%5C(task.bucket)%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0print(%22upload%C2%A0completed2%C2%A0%5C(String(describing%3A%C2%A0task.response))%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0print(%22upload%C2%A0completed3%C2%A0%5C(task.key)%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A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C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0return%C2%A0nil%3B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D” message=”” highlight=”” provider=”manual”/]

In the above method, near “BUCKET NAME” specify the bucket name you had created in AWS and as well let the key be your image name.  The image name should be unique. Else if we use the same image name, it will get replaced in s3 bucket.

So, it’s better we use the current time in milliseconds to be unique. The KEY plays the important role as we can identify the images only with that KEY.

At this point you can run the application and see app showing the interface. Select the image and upload that to S3. Once you get success log, you can go to the S3 in AWS console and check the image there.

Notes:

1. If your image is not appeared in the S3 bucket, then it might be due to some S3 policies issues. You can check the details about policies here. Policies are nothing but the permissions that we have to give to the bucket. So for now let’s go with the default policy which will give the read and write access to the bucket.

[pastacode lang=”cpp” manual=”%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%22Version%22%3A%C2%A0%222012-10-17%22%2C%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%22Statement%22%3A%C2%A0%5B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%22Sid%22%3A%C2%A0%22AddPerm%22%2C%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%22Effect%22%3A%C2%A0%22Allow%22%2C%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%22Principal%22%3A%C2%A0%22*%22%2C%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%22Action%22%3A%C2%A0%22s3%3AGetObject%22%2C%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%22Resource%22%3A%C2%A0%22arn%3Aaws%3As3%3A%3A%3AYOUR%20BUCKET%20NAME%2F*%22%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%5D%C2%A0%C2%A0%0A%7D” message=”” highlight=”” provider=”manual”/]

2. And one important thing you should remember is about the region of S3 bucket. We need to have the S3 bucket in the same region of your account or the region that cognito pool id is generated. (you can check this in the AWS SDK configuration steps that are listed above and in the “awsconfiguration.json” that is generated while setting up the app in AWS mobile hub). It should be mostly “USEAST-1” which is (US-EAST (N.Virginia)).

Once the above configuration is done correctly, re-run the app and upload an image. And now you can see the image in S3 bucket. Incase if you are still not able to see the image please repeat the above steps again and see if anything is wrong. Mainly don’t forget about the S3 bucket policies and region.

Listing the images from S3

Add another Swift class to the Xcode project and set-up the UITableview in that class in storyboard or via programmatically to list the images that are stored in the S3 bucket. Lets name it as “ImagesListView.Swift” for now.

Add a bar button in the ViewController class where we had set-up image upload and set the segue for that barbutton to show this list.

In “ImagesListView.Swift”, lets add the following code to get the images list. Define an array of any object to store the images list and load in tableview and add the following method to get the list of objects from S3 bucket.

To get this method working, we have to update our info.plist file with the following options.

[pastacode lang=”cpp” manual=”AWS%C2%A0–%3E%C2%A0CredentialsProvider%C2%A0–%3E%C2%A0CognitoIdentity%C2%A0–%3E%C2%A0Default%C2%A0–%3E%C2%A0PoolId%C2%A0(put%C2%A0your%C2%A0Cognito%C2%A0IdentityPoolID%C2%A0here)%C2%A0%C2%A0%0AAWS%C2%A0–%3E%C2%A0CredentialsProvider%C2%A0–%3E%C2%A0CognitoIdentity%C2%A0–%3E%C2%A0Default%C2%A0–%3E%C2%A0Region%C2%A0(for%C2%A0example%3A%C2%A0USEast1)%C2%A0%C2%A0%0AAWS%C2%A0–%3E%C2%A0S3TransferUtility%C2%A0–%3E%C2%A0Default%C2%A0–%3E%C2%A0Region%C2%A0(for%C2%A0example%3A%C2%A0USEast1)%C2%A0%C2%A0%0A%C2%A0%C2%A0%0A%3Ckey%3EAWS%3C%2Fkey%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%3Cdict%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3Ckey%3ECredentialsProvider%3C%2Fkey%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3Cdict%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3Ckey%3ECognitoIdentity%3C%2Fkey%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3Cdict%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3Ckey%3EDefault%3C%2Fkey%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%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A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3Ckey%3EDefault%3C%2Fkey%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3Cdict%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3Ckey%3ERegion%3C%2Fkey%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3Cstring%3E%20REGION%20%3C%2Fstring%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3C%2Fdict%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%3C%2Fdict%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%3C%2Fdict%3E” message=”” highlight=”” provider=”manual”/]

Add the following code.

[pastacode lang=”cpp” manual=”import%C2%A0AWSS3%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%0Afunc%C2%A0listS3Objects()%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0credentialProvider%C2%A0%3D%C2%A0AWSCognitoCredentialsProvider(regionType%3A%C2%A0%3CBUCKET%C2%A0REGION%3E%2C%C2%A0identityPoolId%3A%C2%A0%3CPOOL%C2%A0ID%C2%A0listed%C2%A0in%C2%A0aws%C2%A0configuration.json%C2%A0file%3E)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0configuration%C2%A0%3D%C2%A0AWSServiceConfiguration(region%3A%C2%A0%3CREGION%3E%2C%C2%A0credentialsProvider%3A%C2%A0credentialProvider)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0AWSServiceManager.default().defaultServiceConfiguration%C2%A0%3D%C2%A0configuration%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0AWSS3.register(with%3A%C2%A0configuration!%2C%C2%A0forKey%3A%C2%A0%22defaultKey%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0s3%C2%A0%3D%C2%A0AWSS3.s3(forKey%3A%C2%A0%22defaultKey%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0listRequest%3A%C2%A0AWSS3ListObjectsRequest%C2%A0%3D%C2%A0AWSS3ListObjectsRequest()%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0listRequest.bucket%C2%A0%3D%C2%A0%3CBUCKET%C2%A0NAME%3E%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0s3.listObjects(listRequest).continueWith%C2%A0%7B%C2%A0(task)%C2%A0-%3E%C2%A0AnyObject%3F%C2%A0in%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0print(%22Object%C2%A0result%C2%A0%3D%C2%A0%5C(task.result)%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0print(%22Object%C2%A0contents%C2%A0%3D%C2%A0%5C(task.result%3F.contents)%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0for%C2%A0object%C2%A0in%C2%A0(task.result%3F.contents)!%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0print(%22Object%C2%A0key%C2%A0%3D%C2%A0%5C(object.key!)%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0self.imagesArray.append(object)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2Fself.tableView.reloadData()%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0DispatchQueue.main.async%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0self.tableView.reloadData()%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2Fself.tableView.reloadData()%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0return%C2%A0nil%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D” message=”” highlight=”” provider=”manual”/]

Add the following code in respective tableview delegate & datasource methods

[pastacode lang=”cpp” manual=”override%C2%A0func%C2%A0tableView(_%C2%A0tableView%3A%C2%A0UITableView%2C%C2%A0heightForRowAt%C2%A0indexPath%3A%C2%A0IndexPath)%C2%A0-%3E%C2%A0CGFloat%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0return%C2%A0100%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0Aoverride%C2%A0func%C2%A0numberOfSections(in%C2%A0tableView%3A%C2%A0UITableView)%C2%A0-%3E%C2%A0Int%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0return%C2%A01%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0override%C2%A0func%C2%A0tableView(_%C2%A0tableView%3A%C2%A0UITableView%2C%C2%A0numberOfRowsInSection%C2%A0section%3A%C2%A0Int)%C2%A0-%3E%C2%A0Int%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0return%C2%A0self.imagesArray.count%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0override%C2%A0func%C2%A0tableView(_%C2%A0tableView%3A%C2%A0UITableView%2C%C2%A0cellForRowAt%C2%A0indexPath%3A%C2%A0IndexPath)%C2%A0-%3E%C2%A0UITableViewCell%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0cell%C2%A0%3D%C2%A0tableView.dequeueReusableCell(withIdentifier%3A%C2%A0%22imgcell%22%2C%C2%A0for%3A%C2%A0indexPath)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0s3ImageObj%C2%A0%3D%C2%A0self.imagesArray%5BindexPath.row%5D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0finalUrl%C2%A0%3D%C2%A0self.s3Url%C2%A0%2B%C2%A0s3ImageObj.key%C2%A0.%C2%A0%2F%2F%C2%A0here%C2%A0the%C2%A0S3Url%C2%A0should%C2%A0be%C2%A0hardcoded.%C2%A0The%C2%A0url%C2%A0will%C2%A0be%C2%A0available%C2%A0in%C2%A0the%C2%A0S3%C2%A0bucket.%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0print(%22the%C2%A0final%C2%A0url%C2%A0is%C2%A0%5C(finalUrl)%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0imageV%C2%A0%3D%C2%A0cell.viewWithTag(1000)%C2%A0as!%C2%A0UIImageView%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0imageV.loadImageUsingCache(withUrl%3A%C2%A0finalUrl)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0return%C2%A0cell%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D” message=”” highlight=”” provider=”manual”/]

As here we need to load the image from remote url, we need to use Async image loading. Add the following extension at the bottom of the class.

[pastacode lang=”cpp” manual=”let%C2%A0imageCache%C2%A0%3D%C2%A0NSCache%3CNSString%2C%C2%A0AnyObject%3E()%C2%A0%C2%A0%0A%C2%A0%C2%A0%0Aextension%C2%A0UIImageView%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0func%C2%A0loadImageUsingCache(withUrl%C2%A0urlString%C2%A0%3A%C2%A0String)%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0url%C2%A0%3D%C2%A0URL(string%3A%C2%A0urlString)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2Fself.image%C2%A0%3D%C2%A0nil%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2F%C2%A0check%C2%A0cached%C2%A0image%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0if%C2%A0let%C2%A0cachedImage%C2%A0%3D%C2%A0imageCache.object(forKey%3A%C2%A0urlString%C2%A0as%C2%A0NSString)%C2%A0as%3F%C2%A0UIImage%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0self.image%C2%A0%3D%C2%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%C2%A0%C2%A0%0A%7D” message=”” highlight=”” provider=”manual”/]

Run the code to see the images that are uploaded to your s3 bucket.

Let’s see how to delete the images from s3 bucket.

In “ImagesListView.Swift”, lets add a bar button to enable the tableview editing and deleting the selected image from the list and as well from S3 bucket. Write the following code for bar button and respective action.

[pastacode lang=”cpp” manual=”override%C2%A0func%C2%A0viewDidLoad()%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0super.viewDidLoad()%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0editButton%C2%A0%3D%C2%A0UIBarButtonItem(title%3A%C2%A0%22Edit%22%2C%C2%A0style%3A%C2%A0.plain%2C%C2%A0target%3A%C2%A0self%2C%C2%A0action%3A%C2%A0%23selector(enableEdit))%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0self.navigationItem.rightBarButtonItem%C2%A0%3D%C2%A0editButton%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0self.title%C2%A0%3D%C2%A0%22Images%C2%A0List%22%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0listS3Objects()%C2%A0%C2%A0%0A%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0tableView.dataSource%C2%A0%3D%C2%A0self%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0tableView.delegate%C2%A0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0%3D%C2%A0true%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0self.navigationItem.rightBarButtonItem%3F.title%C2%A0%3D%C2%A0%22Done%22%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D” message=”” highlight=”” provider=”manual”/]

Once the “Edit” is clicked, the tableview will be in edit mode with default delete buttons. You can select any image and delete it. So to get that image deleted from list and as well from s3 bucket write the following code.

Tableview Delegate method:

[pastacode lang=”cpp” manual=”override%C2%A0func%C2%A0tableView(_%C2%A0tableView%3A%C2%A0UITableView%2C%C2%A0commit%C2%A0editingStyle%3A%C2%A0UITableViewCellEditingStyle%2C%C2%A0forRowAt%C2%A0indexPath%3A%C2%A0IndexPath)%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0if%C2%A0editingStyle%C2%A0%3D%3D%C2%A0.delete%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2F%C2%A0Delete%C2%A0the%C2%A0row%C2%A0from%C2%A0the%C2%A0data%C2%A0source%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0s3ImageObj%C2%A0%3D%C2%A0self.imagesArray%5BindexPath.row%5D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0self.deleteS3Object(imageKey%3A%C2%A0s3ImageObj.key)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0self.imagesArray.remove(at%3A%C2%A0indexPath.row)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0tableView.deleteRows(at%3A%C2%A0%5BindexPath%5D%2C%C2%A0with%3A%C2%A0.fade)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0else%C2%A0if%C2%A0editingStyle%C2%A0%3D%3D%C2%A0.insert%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2F%2F%C2%A0Create%C2%A0a%C2%A0new%C2%A0instance%C2%A0of%C2%A0the%C2%A0appropriate%C2%A0class%2C%C2%A0insert%C2%A0it%C2%A0into%C2%A0the%C2%A0array%2C%C2%A0and%C2%A0add%C2%A0a%C2%A0new%C2%A0row%C2%A0to%C2%A0the%C2%A0table%C2%A0view%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%7D” message=”” highlight=”” provider=”manual”/]

And Delete image from bucket:

[pastacode lang=”cpp” manual=”func%C2%A0deleteS3Object(imageKey%C2%A0%3A%C2%A0String)%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0credentialProvider%C2%A0%3D%C2%A0AWSCognitoCredentialsProvider(regionType%3A%C2%A0%3CREGION%3E%2C%C2%A0identityPoolId%3A%C2%A0%3CPOOL%C2%A0ID%C2%A0listed%C2%A0in%C2%A0aws%C2%A0configuration.json%C2%A0file%3E)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0configuration%C2%A0%3D%C2%A0AWSServiceConfiguration(region%3A%C2%A0%3CREGION%3E%2C%C2%A0credentialsProvider%3A%C2%A0credentialProvider)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0AWSServiceManager.default().defaultServiceConfiguration%C2%A0%3D%C2%A0configuration%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0AWSS3.register(with%3A%C2%A0configuration!%2C%C2%A0forKey%3A%C2%A0%22defaultKey%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0s3%C2%A0%3D%C2%A0AWSS3.s3(forKey%3A%C2%A0%22defaultKey%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0let%C2%A0deleteObjectRequest%C2%A0%3D%C2%A0AWSS3DeleteObjectRequest()%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0deleteObjectRequest%3F.bucket%C2%A0%3D%C2%A0%22%3CBUCKET%C2%A0NAME%3E%22%C2%A0%2F%2F%C2%A0bucket%C2%A0name%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0deleteObjectRequest%3F.key%C2%A0%3D%C2%A0imageKey%C2%A0%2F%2F%C2%A0File%C2%A0name%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0s3.deleteObject(deleteObjectRequest!).continueWith%C2%A0%7B%C2%A0(task%3AAWSTask)%C2%A0-%3E%C2%A0AnyObject%3F%C2%A0in%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0if%C2%A0let%C2%A0error%C2%A0%3D%C2%A0task.error%C2%A0%7B%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0print(%22Error%C2%A0occurred%3A%C2%A0%5C(error)%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0return%C2%A0nil%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0print(%22Bucket%C2%A0deleted%C2%A0successfully.%22)%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0return%C2%A0nil%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%7D%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%0A%C2%A0%C2%A0%C2%A0%7D” message=”” highlight=”” provider=”manual”/]

You can run the app and if everything is done correctly as listed above, then you can upload the images, List the images and Remove the images to and from your AWS S3 bucket.

The final output:

Using Realm Mobile Database