Dropbox API 使用SwiftyDropbox库下载包含进度信息的文件
示例
根据本教程改编而成,它使用SwiftyDropbox库下载文件,并使用download方法上的进度回调来获取进度信息:
//下载档案
let destination : (NSURL, NSHTTPURLResponse) -> NSURL = { temporaryURL, response in
let fileManager = NSFileManager.defaultManager()
let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
//为这个文件生成一个唯一的名称,以防我们之前见过它
let UUID = NSUUID().UUIDString
let pathComponent = "\(UUID)-\(response.suggestedFilename!)"
return directoryURL.URLByAppendingPathComponent(pathComponent)
}
Dropbox.authorizedClient!.files.download(path: "/path/to/Dropbox/file", destination: destination)
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
print("bytesRead: \(bytesRead)")
print("totalBytesRead: \(totalBytesRead)")
print("totalBytesExpectedToRead: \(totalBytesExpectedToRead)")
}
.response { response, error in
if let (metadata, url) = response {
print("*** Download file ***")
print("Downloaded file name: \(metadata.name)")
print("Downloaded file url: \(url)")
} else {
print(error!)
}
}然后,您可以使用该原始进度信息来备份应用程序中的进度UI。
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短