Swift - AWS S3 Upload Image from Photo Library and download it

后端 未结 3 1894
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 10:41

I\'ve looked many amazon docs but didn\'t find enough information to upload and download images to S3 using Swift.
How can I do that?

3条回答
  •  心在旅途
    2020-12-15 11:19

    func uploadFile(with resource: String, type: String) {
            let key = "\(resource).\(type)"
            let localImagePath = Bundle.main.path(forResource: resource, ofType: type)
            let localImageUrl = URL(fileURLWithPath: localImagePath!)
            let transferManager1 = AWSS3TransferUtility.default()
            let expression = AWSS3TransferUtilityUploadExpression()
            self.uploadCompletionHandler = { (task, error) -> Void in
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: {
                    if ((error) != nil){
                        print("Failed with error")
                        print("Error: \(error!)");
                    }
                    else{
                        print("Sucess")
                    }
                })
            }
            let transferUtility = AWSS3TransferUtility.default()
            transferUtility.uploadFile(localImageUrl, bucket: "", key: key, contentType: "video/mov", expression: expression, completionHandler: uploadCompletionHandler).continueWith { (task) -> AnyObject? in
                if let error = task.error {
                    print("Error: \(error.localizedDescription)")
                }
                if let _ = task.result {
                    print("Upload Starting!")
                }
                return nil;
            }
        }
    @IBAction func uplaodVideo(){
        uploadFile(with: "random", type: "mov")
    }
    

提交回复
热议问题