HomeiOS DevelopmentUnable to add picture utilizing AWSS3 SDK in iOS Swift

Unable to add picture utilizing AWSS3 SDK in iOS Swift


I have to add solely photos in AWSS3 bucket, so I’ve put in pod AWSS3 and pod AWSCore

my iOS model is 13.0 and swift is as much as 5

and bucket additionally created in AWS

in line with this accepted reply upload-image-aws-s3-bucket-in-swift I’ve wrote code like under

func uploadButtonPressed() {
        if myimageView.picture == nil {
            // Do one thing to get up consumer :)
        } else {
            let picture = myimageView.picture!
            let fileManager = FileManager.default
            let path = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent("test3.jpeg")
            let imageData = UIImageJPEGRepresentation(picture, 0)
            fileManager.createFile(atPath: path as String, contents: imageData, attributes: nil)

            let fileUrl = NSURL(fileURLWithPath: path)
            let uploadRequest = AWSS3TransferManagerUploadRequest()
            uploadRequest?.bucket = "<Your Bucket Identify>"
            uploadRequest?.key = "<Picture Identify>"
            uploadRequest?.contentType = "picture/jpeg"
            uploadRequest?.physique = fileUrl as URL!
            uploadRequest?.serverSideEncryption = AWSS3ServerSideEncryption.awsKms
            uploadRequest?.uploadProgress = { (bytesSent, totalBytesSent, totalBytesExpectedToSend) -> Void in
                DispatchQueue.important.async(execute: {
//                    print("totalBytesSent",totalBytesSent)
//                    print("totalBytesExpectedToSend",totalBytesExpectedToSend)

//                    self.amountUploaded = totalBytesSent // To indicate the updating knowledge standing in label.
//                    self.fileSize = totalBytesExpectedToSend
                })
            }

            let transferManager = AWSS3TransferManager.default()
            transferManager.add(uploadRequest!).continueWith(executor: AWSExecutor.mainThread(), block: { (job:AWSTask<AnyObject>) -> Any? in
            if job.error != nil {
                    // Error.
                print("error")
                } else {
                    // Do one thing along with your outcome.
                print("No error Add Performed")
                }
                return nil
            })
        }
    }

error:

Can’t discover ‘AWSS3TransferManagerUploadRequest’ in scope

so tried up to date swift model code: right here i’ve given all my bucket particulars and dont know the place to name that technique so utilized in viewWillAppear however its neither printing Success AWSS3 picture nor print error (error)

find out how to and the place to name uploadS3 this technique and in my under code the place am i fallacious?

Learn how to add photos in AWSS3, please information me

override func viewWillAppear(_ animated: Bool) {
    tremendous.viewWillAppear(animated)

func uploadS3(picture: UIImage,
          identify: String,
          progressHandler: @escaping (Progress) -> Void,
          completionHandler: @escaping (Error?) -> Void) {

let picture = UIImage(named: "home-bucket")

guard let knowledge = picture?.jpegData(compressionQuality: 0.75) else { return }


let credentialsProvider = AWSStaticCredentialsProvider(accessKey: "gdbshjfgdsjhf", secretKey: "gefhjsdfbjdhs")
let configuration = AWSServiceConfiguration(area: .EUWest2, credentialsProvider: credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
let expression = AWSS3TransferUtilityUploadExpression()
expression.progressBlock = { job, progress in
    DispatchQueue.important.async {
        progressHandler(progress)
    }
}

AWSS3TransferUtility.default().uploadData(
    knowledge,
    bucket: "appnameearth",
    key: "home-bucket",
    contentType: "picture/jpg",
    expression: expression) { job, error in
      
        print("Success AWSS3 picture")
        
    }.continueWith { job -> AnyObject? in
        if let error = job.error {
            print("print error (error)")
        }
        return nil
    }
}
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments