August 2018 - Added Upload example
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:
Using is is very easy:
Create a **SCDPlatformCamera** instance
Use the **getPicture** method to invoke native camera api
You have two options to choose from. **Picture** or **PhotoLibrary**.
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.
You can doublecheck the successful upload by retrieving the image in the browser