GithubHelp home page GithubHelp logo

mikezucc / datacortex Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 16 KB

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

License: MIT License

Swift 100.00%

datacortex's Introduction

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()

datacortex's People

Contributors

mikezucc avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.