func loadAsyncWithCacheFromAWSS3(_ link: String,fromBucket:String ,border:UIColor? = UIColor.black, showLabelBackground:Bool ,placeholder: UIImage? = UIImage(named: "placeholder")) { let getPreSignedURLRequest = AWSS3GetPreSignedURLRequest() getPreSignedURLRequest.bucket = fromBucket getPreSignedURLRequest.key = link getPreSignedURLRequest.httpMethod = .GET getPreSignedURLRequest.expires = Date(timeIntervalSinceNow: 3600) // Change the value of the expires time interval as required AWSS3PreSignedURLBuilder.default().getPreSignedURL(getPreSignedURLRequest).continueWith { (task:AWSTask) -> Any? in if let error = task.error as NSError? { print("Error: \(error)") return nil } if let presignedURL = task.result { DispatchQueue.main.async { self.backgroundColor = Theme.SF_BACKGROUND_COLOR self.layer.cornerRadius = self.frame.size.width/2 self.layer.shadowColor = UIColor.black.cgColor self.layer.shadowOffset = CGSize(width: 5.0, height: 5.0) self.layer.shadowRadius = 15.0 self.layer.shadowOpacity = 0.3 if showLabelBackground { self.labelBackground!.backgroundColor = Theme.SF_BACKGROUND_COLOR self.labelBackground!.alpha = 0.5 self.imageView.addSubview(self.labelBackground!) } self.imageView.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height) self.imageView.kf.setImage(with: ImageResource(downloadURL: URL(string: presignedURL.absoluteString!)!, cacheKey: link)) self.imageView.layer.cornerRadius = self.imageView.frame.size.width/2 self.imageView.clipsToBounds = true self.imageView.layer.borderWidth = 1 self.imageView.layer.borderColor = border?.cgColor self.imageView.contentMode = .scaleAspectFill self.addSubview(self.imageView) } } return nil } }