你可以尝试使用RxSwift https://github.com/ReactiveX/RxSwift框架。就像是...
// Multiple image uploading
RRAWSRxUpload.upload(dataList: [AWSImageData(type: .image1, image: #imageLiteral(resourceName: "image1")), AWSImageData(type: .image2, image: #imageLiteral(resourceName: "image2"))])
.subscribeOn(ConcurrentDispatchQueueScheduler.init(qos: .background))
.observeOn(MainScheduler.instance)
.subscribe(onNext: { response in
print(response)
//Get here all file uploaded key names after that you will call your server API call to update those files.
}, onError: { error in
print(error.localizedDescription)
}).disposed(by: rxbag)
另外,请在 GitHub 演示上了解更多详细信息RRAWSRX上传 https://github.com/Rahul-Mayani/RRAWSRxUpload.
你还可以通过 RxSwift 调用你的服务器 API阿拉莫菲尔 https://github.com/Alamofire/Alamofire图书馆。
完成 AWS S3 上传部分后,您将通过以下方式调用服务器 Alamofire API 请求RRAlamofireRxAPI https://github.com/Rahul-Mayani/RRAlamofireRxAPI.
RRAWSRxUpload.upload(dataList: [AWSImageData(type: .image1, image: #imageLiteral(resourceName: "image1")), AWSImageData(type: .image2, image: #imageLiteral(resourceName: "image2"))])
.flatMap { (keys) -> Observable<DataModelObject> in
print(keys)// pass your files array/model to your server as parameters
return RRAPIRxManager.rxCall(apiUrl: APIEndPoint.Name.uploadAWSImage, httpMethod: .post, param: parameters)
}
.subscribeOn(RXScheduler.concurrentBackground)
.observeOn(RXScheduler.main)
.subscribe(onNext: {(response) in
print(response)
}, onError: { (error) in
print(error)
}).disposed(by: rxbag)