in OSSSwiftDemo/OSSSwiftDemoTests/OSSNormalObjectTests.swift [332:367]
func testAPI_getObjectOverwriteOldFile() -> Void {
let localFileName = "test_overwrite"
let localFilePath = (documentDirectory! as NSString).appendingPathComponent(localFileName)
var request = OSSGetObjectRequest()
request.bucketName = OSS_BUCKET_PRIVATE
request.objectKey = fileNames[0]
request.downloadProgress = { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) -> Void in
OSSLogVerbose("bytesWritten: \(bytesWritten), totalBytesWritten: \(totalBytesWritten), totalBytesExpectedToWrite: \(totalBytesExpectedToWrite)")
}
request.downloadToFileURL = URL.init(fileURLWithPath: localFilePath)
var task = client.getObject(request)
task.continue({ (t) -> Any? in
XCTAssertNil(t.error)
return nil
}).waitUntilFinished()
request = OSSGetObjectRequest()
request.bucketName = OSS_BUCKET_PRIVATE
request.objectKey = fileNames[2]
request.downloadProgress = { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) -> Void in
OSSLogVerbose("bytesWritten: \(bytesWritten), totalBytesWritten: \(totalBytesWritten), totalBytesExpectedToWrite: \(totalBytesExpectedToWrite)")
}
request.downloadToFileURL = URL.init(fileURLWithPath: localFilePath)
task = client.getObject(request)
task.continue({ (t) -> Any? in
XCTAssertNil(t.error)
let result = t.result as! OSSGetObjectResult
let contentLength = result.objectMeta[OSS_CONTENT_LENGTH]
let localFileSize = try! FileManager.default.attributesOfItem(atPath: localFilePath)[FileAttributeKey.size]
XCTAssertEqual(String(describing: contentLength!), String(describing: localFileSize!))
return nil
}).waitUntilFinished()
}