in OSSSwiftDemo/OSSSwiftDemoTests/SequentialMultipartUploadTests.swift [160:204]
func testAPI_sequentialMultipartUpload_cancel_and_resume_crcOpened() {
var request = OSSResumableUploadRequest()
request.bucketName = OSS_BUCKET_PUBLIC;
request.objectKey = "sequential-swift-multipart";
request.uploadingFileURL = Bundle.main.url(forResource: "wangwang", withExtension: "zip")!
request.deleteUploadIdOnCancelling = false
request.crcFlag = OSSRequestCRCFlag.open
request.recordDirectoryPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!
request.uploadProgress = {[weak request](bytesSent, totalBytesSent, totalBytesExpectedToSend) in
if totalBytesSent > totalBytesExpectedToSend / 2 {
request?.cancel()
}
}
let filePath = Bundle.main.path(forResource: "wangwang", ofType: "zip")
request.contentSHA1 = OSSUtil.sha1(withFilePath: filePath)
var task = client.sequentialMultipartUpload(request)
task.continue({ (t) -> Any? in
XCTAssertNotNil(t.error)
let error = t.error! as NSError
XCTAssertEqual(error.code, OSSClientErrorCODE.codeTaskCancelled.rawValue)
return nil;
}).waitUntilFinished()
request = OSSResumableUploadRequest()
request.bucketName = OSS_BUCKET_PUBLIC;
request.objectKey = "sequential-swift-multipart";
request.uploadingFileURL = Bundle.main.url(forResource: "wangwang", withExtension: "zip")!
request.deleteUploadIdOnCancelling = true
request.crcFlag = OSSRequestCRCFlag.open
request.contentSHA1 = OSSUtil.sha1(withFilePath: filePath)
request.recordDirectoryPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!
request.uploadProgress = {(bytesSent, totalBytesSent, totalBytesExpectedToSend) in
print("bytesSent: \(bytesSent), totalBytesSent: \(totalBytesSent), totalBytesExpectedToSend: \(totalBytesExpectedToSend)")
}
task = client.sequentialMultipartUpload(request)
task.continue({ (t) -> Any? in
XCTAssertNil(t.error)
return nil
}).waitUntilFinished()
}