2020-05-08 17:49:14 +10:00
|
|
|
//
|
|
|
|
// DataUploadS3.swift
|
|
|
|
// CovidSafe
|
|
|
|
//
|
|
|
|
// Copyright © 2020 Australian Government. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
class DataUploadS3 {
|
2021-02-02 11:04:43 +11:00
|
|
|
static func uploadJSONData(data: Data, presignedUrl: String, completion: @escaping (Bool, Swift.Error?, String?) -> Void) {
|
2020-05-08 17:49:14 +10:00
|
|
|
guard let url = URL(string: presignedUrl) else {
|
2021-02-02 11:04:43 +11:00
|
|
|
completion(false, nil, "[102] S3")
|
2020-05-08 17:49:14 +10:00
|
|
|
return
|
|
|
|
}
|
|
|
|
var request = URLRequest(url: url)
|
|
|
|
request.httpMethod = "PUT"
|
|
|
|
|
|
|
|
let uploadRequest = CovidNetworking.shared.session.upload(data,
|
|
|
|
with: request,
|
|
|
|
interceptor: CovidRequestRetrier(retries: 3)
|
|
|
|
).validate().response { (response) in
|
|
|
|
switch response.result {
|
|
|
|
case .success:
|
2021-02-02 11:04:43 +11:00
|
|
|
completion(true, nil, nil)
|
2020-05-08 17:49:14 +10:00
|
|
|
case let .failure(error):
|
2021-02-02 11:04:43 +11:00
|
|
|
completion(false, error, "[\(response.response?.statusCode ?? 000))] S3")
|
2020-05-08 17:49:14 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
uploadRequest.resume()
|
|
|
|
}
|
|
|
|
}
|