I'm using this code which is a mildly doctored version of an online tutorial. I understand the parts, but when I run it, the downloads happen, I get an error-free completion message. But the resulting file is truncated at 209 bytes (should be much larger).
func dl( request: URL, dest: URL) {
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, error == nil {
// Success
if let statusCode = (response as? HTTPURLResponse)?.statusCode {
print("Successfully downloaded. Status code: \(statusCode)")
}
do {
try FileManager.default.copyItem(at: tempLocalUrl, to: dest)
} catch (let writeError) {
print("Error creating file \(dest) : \(writeError)")
}
} else {
print("Error while downloading. Error : %@", error?.localizedDescription);
}
}
task.resume()
}
The source file is on my iCloud, with permissions set to anyone with the link. When I try urls on other sites, it works fine.
I haven't been able to find a reliable, recent guide to doing what I'm trying to do, but from iCloud.... what am I missing?