Since AWS's official library is extremely complicated, I decided to make one to simplify the work. All asynchrony is performed using PromiseKit. You need to know the concept of promise; if you don't know, see it.
- Clone the repo
- Run
pod install
from the Example directory first - Open
AppDelegate.swift
- Update
application(_:didFinishLaunchingWithOptions)
with your Amazon's credentials
RuAWSS3 is available through CocoaPods. To install it, add the following line to your Podfile:
pod 'RuAWSS3', '~> 0.1.0-beta'
And, add in your AppDelegate.swift
:
import RuAWSS3
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
AmazonS3.shared.performCredentials(
regionType: ** YOUR REGION **,
identityPoolId: ** YOUR POOL ID **
)
return true
}
Firstly, you need import this modules:
import PromiseKit
import RuAWSS3
Upload image
firstly {
AmazonS3.shared.uploadImage(
bucket: "example",
key: "image.jpg",
    image: UIImage(named: "example")!
  )
}.then {
  print("succes õ/")
}.catch { error in
  print("fail ;-;")
print((error as NSError).localizedDescription)
}
Download image
firstly {
AmazonS3.shared.download(
bucket: "example",
key: "image.jpg"
)
}.then { filePath -> Void in
  print("succes õ/")
self.imgView.image = UIImage(contentsOfFile: filePath)!
}.catch { error in
  print("fail ;-;")
print((error as NSError).localizedDescription)
}
Delete file
firstly {
AmazonS3.shared.delete(
bucket: "example",
key: "image.jpg"
)
}.then {
  print("succes õ/")
}.catch { error in
  print("fail ;-;")
print((error as NSError).localizedDescription)
}
You can see others amazing examples in Example application.
Macabeus, [email protected]
RuAWSS3 is available under the MIT license. See the LICENSE file for more info.