Swift3: Uploading Image with Serverless Platform Skygear

This tutorial is written for Skygear, a backend-as-a-service (BaaS) that helps you build serverless apps. Skygear includes features such as push notifications, cloud database, and user authentication.

Go Serverless

Almost any app these days has a photo uploading feature. Whether it’s a social app or a review platform, a photo uploading feature is essential for gathering user-generated content. A feature like this shouldn’t take a whole day to write. Here’s a walkthrough for you to develop a simple app that allows you to upload images and share them using Skygear.

As mentioned, Skygear is a serverless platform for building apps. One of the features, Skygear CloudDB, enables you to upload your user-generated content  to the cloud storage. This content can be  images, videos, or even audio files. The files will be hosted in the cloud and made available for your mobile app clients. You can download the Swift photo feed demo and run on Xcode to see how photo upload works.

Setup your Skygear backend

First thing, in this example, you have to initialize Skygear before any Skygear app reference is created or used. If you have already done this for another Skygear feature, you can skip this step.

Initialize Skygear:

  1. Create your app backend on Skygear Portal (2 mins)
  2. Install the Skygear SDK (10 mins)
  3. Import SKYKit module & other configuration into your code (3 mins)

You can follow  this step-by-step iOS guide to initialize Skygear.

Uploading a photo

Ok. Let’s start implementing the uploading photos feature. In Skygear, you can make use of Asset to store file references, such as images and videos on the database. Let’s say, your user has taken a photo. In order to have the photo uploaded, we will call the uploadAsset API to upload the photo image file as an asset.

In the above sample code, we define an uploadable SKYAsset and set the chosen image data as the asset data. We also set the mimeType of the asset as image/jpg. Upon calling uploadAssest, the asset assigned will be uploaded. Then we pass to the completionHandler to handle success / fail upload case.

You can check the full list of supported mime types here

Saving the asset with a photo record

Since we want to query the photo later, we have to save the image to the cloud database.
In Skygear, an asset can only be saved with a record but not as a standalone upload. We will create a photo record and assign the uploaded asset as asset of the record.

Fetching the uploaded photos

Now, we want to load back the photos we’ve uploaded through the app.

To access the photos, we need to query the photo records. We can directly access the uploaded asset with SKYAsset.url .

As a result, we have imageAsset.url in hand , so we can load back the image and display it on any device.

To learn more about Skygear
In addition to images, you can also upload other file types (such as voice messages, PDF files, live recordings, etc) to the serverless platform. Please see detailed documentation about file uploading here: Skygear iOS Assets (File Upload). If you need my support on trying it out, just ping me (David) on Skygear Google Group.


Tell us what you think and subscribe to our blog for more project updates!


Follow us on Twitter to get updates.

An IoT Side Project: Chima-open-door

When Oursky moved into a new office in Lai Chi Kok, my colleagues discovered that there was no guide to reset the door lock left by the last tenant. Firstly, we were too cheap to replace it, and secondly, it was a great chance to implement an open door feature with some new tech (fiddling with a bit of IoT). (Ok! I admit it is a bit over-engineered! But we just love it!) I also hope no one needs to get up to open the door when the doorbell rings. Ever.

By the way, I’m Steven, a 3-year Ourskyer specializing in web and native iOS app development. Chima Open Door is one of Oursky’s many side projects — some for fun, and some that actually make money!

Continue reading

Using Tensorflow and Support Vector Machine to Create an Image Classifications Engine

In this post, we are documenting how we used Google’s TensorFlow to build this image recognition engine. We’ve used Inception to process the images and then train an SVM classifier to recognise the object. Our aim is to build a system that helps a user with a zip puller to find a matching puller in the database. This piece will also cover how the Inception network sees the input images and assess how well the extracted features can be classified. Continue reading

11 Command Line Tips That You Probably Missed

A list of command line tips to optimize your terminal experience. All the recommended features are linked to their appropriate sources. Continue reading

Open Source AWS S3 and CloudFront Site-Manager

Ever wanted a simple, affordable and feature-rich hosting for your custom domain? AWS S3 + Cloudfront combined is a great static site hosting solution, but can be troublesome to setup. You need to setup the S3 correctly, configurable Cloudfront, worry about best practices such as site redirection, sync file and invalidate Cloudfront for update, etc. These are just too troublesome for hosting a static sites, so we open-sourced our tool AWS-site-manager. AWS Site Manager is a simple command-line tool which makes hosting a static website with AWS S3 and CloudFront in best practices really simple.

Continue reading

Software Testing World Cup 2016 Recap: 7 Critical Learnings You May have Missed

Last week, while people were thinking about the weekend, 4 Ourskyers got together to join the Software Testing World Cup 2016 (STWC) Asia Competition,  one of the leading events for the software testing community. Testers from all over the world will team up and join the competition to train up their skills and take home the crown. Roy, Oliver, Ten and I (Joyz) come from different positions in Oursky formed a 1-day team to join this exciting opportunity. I’d like to share with you the things we learned during the 3 hours we had against the rest of the world to test a mobile app.
Continue reading

Offline-First: No More Network Connection Error

The Internet seems to be always available nowadays. Thanks to the mobility of phones and tablets, mobile app developers can design their apps with a variety of features that assume the Internet connection is stable and let users experience tithe unleash the power of the convenient and efficient network services. Social media apps such as Facebook, WhatsApp and Instagram are good examples. However, how would theses apps function when there is no stable internet connection?

“No Network” bugs are hard to dig out.

When an app puts cloud services as its major selling point, it would be often running into various Network Connection Errors. You will see a lot of these issues from the bug report from testers.

The problem only scales up with the project size. And – it makes developers headache – it is hard to gid out all “No Network” related bugs. Often, apps are developed at a company that serves ultra-high performance network.

Developers cannot react quick to fix problem will have to receive “1-star rating App Reviews” on App Store or Play Store hopelessly.

Do not assume the Internet is always reachable.

Start building an app with the Online-First pattern does speed up the progress in early stage development, yet it might become a crisis in a later stage. If your apps rely heavily on the Internet connection, you should be more proactively take network instability problems into account earlier. Hence, the concept “offline-first” was introduced.

Continue reading

Ethereum 101: Blockchain as Distributed Computation Platform

Editor’s Note: Chung is an Oursky Intern. After participating in our Smart Contract consulting project, he wrote this introductory article to catalog his learnings about the Ethereum network.

You must have heard of Bitcoin, the distributed currency system.

Bitcoin utilizes a technique called blockchain which stores all the transaction records. Blockchain also ensures that no malicious modifications could be applied to the records.

As a distributed system, Bitcoin utilizes machines on the whole network to compute and verify the changes on the records.

What if we go went beyond storing transaction records into program states? This makes the whole network a computer for general purpose computations with program states that no one can modify illegally. Ethereum does this.

Let me explain below.

What is missing from Bitcoin?

Bitcoin blockchain architecture has several problems for general purpose computations. They include network state dependency, Turing-completeness and block time. 

Program States

Bitcoin only stores the transactions of coins in the blockchain. Therefore, the state of the network (implicitly constructed by transaction records) is just the amount of coins for each account. For general purpose computations, we need general purpose program states.

 

Continue reading

Dissecting Famous Egg Dropping Puzzle

egg dropping puzzle

The egg dropping puzzle was one of the key interview questions in Google

Egg Dropping Puzzle (2-egg, 100-floor version)

“Figure out the highest floor of a 100-floor building an egg can be dropped without breaking,  given two eggs”

The Egg Dropping Puzzle is a mathematical puzzle that has been around the internet for some time now, which is known to be adopted in interviews of major companies like Google, Microsoft, Accenture and even Hewlett Packard.

You are to determine the minimum number of attempts required in the worst case scenario to find the critical floor.

 

Continue reading

Journey Through Agile Test Automation

For QA in an agile development team, SPEED is everything. It is a game on a high-speed roundabout, developers introduce new features and fixes every day, and you better test everything before the next iteration. Besides the new features or fixes, you still need to handle a full UI regression smoke test, how is that possible? Hire more staff? Test automation is a way out for smart teams, and that’s what we do at Oursky.

Preparation

The basic aim of Test Automation is to replace repetitive human work with computers.

So, to get started, all you need to do is no more than wrapping up your existing test plans, and to decide which parts are to be automated. If you already have a comprehensive test plan, with step-by-step test cases and well-defined expected results, congratulations! You are perfectly ready for automation.

Or else, some preparation are needed.

Continue reading

« Older posts

© 2017 Oursky Code Blog

Theme by Anders NorenUp ↑