This is likely a very easy answer. I am fairly new to Swift and just getting feet wet with AWS. I simply want to download a JSON file to a string var in Swift so that I can parse, etc. I'm not able to find a good example (other than a repetitive one showing how to download an image).
I've seen the image example where the completion handler accesses the data i.e. UIImage(data: data!)!
but I can't find the equivalent for a text file.
I know that I am getting in via credentials and configuration and that it is all correct. I just can't coax the text data out of the result. Here is the snippet I think should return what I want. I just need to know where it is...
func getJSON() {
let S3BucketName: String = "mybucket"
let S3DownloadKeyName: String = "myfile.txt"
let expression = AWSS3TransferUtilityDownloadExpression()
expression.progressBlock = {(task, progress) in DispatchQueue.main.async(execute: {
print("Downloading...")
})
}
let transferUtility = AWSS3TransferUtility.default()
transferUtility.downloadData(fromBucket: S3BucketName, key: S3DownloadKeyName, expression: expression) { (task, URL, data, error) in
if error != nil {
print(error!)
return
}
DispatchQueue.main.async(execute: {
print("Got here")
// I would expect to find data in an attribute here
})
}
}
I would think the actual string could be coaxed from the "data" value in the completion handler, but I simply am not sure how to reach it or what property it exists in. I'm pretty sure I did an exhaustive search of a similar example that I could understand, but didn't find anything.
Any help is greatly appreciated.