**Change history**

  • August 2018 - Added Upload example

# Introduction

The camera control is not really a control that you pick from the control list, but a class we use to

  • take pictures using the native Android or iOS camera control

  • select from the picture library

The SCDPlatformCamera Class wraps the **UIImagePickerController** for iOS and the **ACTION_IMAGE_CAPTURE** intent for the Android os.

# Minimal Camera app

The layout is simple. We use a bitmap control to show the picture we will take / the image we will select from the library. The two buttons are linked to the getPicture method:

(Script tags will be stripped)


Using is is very easy:

  1. Create a **SCDPlatformCamera** instance

  2. Use the **getPicture** method to invoke native camera api

  3. You have two options to choose from. **Picture** or **PhotoLibrary**.

  4. Create event handlers to react to success and failure

Here the sample code for taking pictures



# Upload image to Cloud server

A common scenario is to upload images taken onto the web, for instance into Amazon S3. This chapter demonstrate how to use a **Http multipart POST** to send your image to the web (www.file.io)

Important - Use isoLatin1 for encoding images from camera

The most important learning is to use <String>.data(using: String.Encoding.**isoLatin1**) to convert the image received from the camera to the Data object.

First, we add a helper class that makes creating a MultiPart request easy. Please pay attention to the code at the end of the file ( isoLatin1 )



Now we can easily create a UrlRequest and use the regular Swift Foundation URLRequest to execute an POST to www.file.io



We added another button to send the captured image to the internet server.

Select a picture and press the upload button and the URL of the uploaded image shows up your IDE console.

(Script tags will be stripped)


You can doublecheck the successful upload by retrieving the image in the browser

(Script tags will be stripped)