Skip to content

AWS S3 is easy! A streamlined class to upload, download, and manage caches for files on AWS S3

License

Notifications You must be signed in to change notification settings

mikezucc/DataCortex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

neura

DataCortex

AWS S3 is easy! A streamlined class to upload, download, and manage caches for files on AWS S3.

Taken from a project I am working to make your life ez pz.

[x] Images, with efficient compression

[ ] Videos, with efficient compression

Configuring

  1. For the following step, please use the identity pool technique, it is confusing AF but it really is better
  2. Follow AWS S3 iOS SDK guide on adding the dependencies and configuration files to your project using Pods
  3. Set your DataCortex.identityPoolId = "us-east-1:<a-long-uuid>"
  4. You're done. Begin using!
  5. If something is not working, enable logging DataCortex.loggingEnabled = true

PUT Images

DataCortex.neura.setImage(image: i,
                          for: ident,
                          completion: { (image, code, progress) in
                                          print("image: \(ident) code: \(code) progress: \(progress)")
                                        })

A full copy-pasta for using PHAsset

let images: [PHAsset] = .... from an image picker
let manager = PHImageManager.default()
let options = PHImageRequestOptions()
options.isSynchronous = false
options.deliveryMode = .highQualityFormat
options.isNetworkAccessAllowed = true // allow this to pull from shared albums, iCloud, etc.

var finishedItems = [UIImage]()
images.compactMap({$0.asset}).forEach { (asset) in
    let aspectRatio = asset.pixelHeight / asset.pixelWidth
    let width = min(asset.pixelWidth, Int(view.bounds.size.width))
    var height = asset.pixelHeight
    if width != asset.pixelWidth {
        height = width * aspectRatio
    }
    manager.requestImage(for: asset,
                         targetSize: CGSize(width: asset.pixelWidth, height: asset.pixelHeight),
                         contentMode: PHImageContentMode.default,
                         options: options,
                         resultHandler: { [weak self] (image, configs) in
                            var ident = asset.localIdentifier
                            ident = ident.replacingOccurrences(of: "/", with: "")
                            guard let i = image else {
                                return
                            }

                            DataCortex.neura.setImage(image: i,
                                                      for: ident,
                                                      completion: { (image, code, progress) in
                                                      print("image: \(ident) code: \(code) progress: \(progress)")
                            })
    })
}

GET Images

let _ = DataCortex.neura.image(for: imageKey) { (image, recallCode, progress) in
                                                    if recallCode != .loaded {
                                                        return
                                                    }
                                                    if let i = image {
                                                        cell?.coverImageView?.image = i
                                                    }
                                                }

Check Cache Size

cacheSizeButton?.setTitle("Clear Cached Media: \(DataCortex.neura.sizeOfMediaCache())MB", for: UIControl.State.normal)

Clear Cache

DataCortex.neura.purgeAllCache()

Let the DataCortex auto-clean up the cache

DataCortex.neura.purgeStaleNeura()

About

AWS S3 is easy! A streamlined class to upload, download, and manage caches for files on AWS S3

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages