的iOS 10.12.3 SWIFT 3.0 SwiftyDropbox 4.1.1稍微更完整的答案上传的另一个150MB的文件上。
func files_saver(sourcePath: String) {
let textContent = "Blah Blah Blah"
let textData:NSData? = textContent.data(using: String.Encoding.utf8) as NSData?
let client = DropboxClientsManager.authorizedClient!
client.files.upload(path: sourcePath, input: textData as! Data).response { response, error in
if let metadata = response {
print("Uploaded file name: \(metadata.name)")
print("Uploaded file revision: \(metadata.rev)")
// Get file (or folder) metadata
}
if let error = error {
switch error as! CallError<SwiftyDropbox.Files.UploadError> {
case .routeError(let boxed, let requestId):
switch boxed.unboxed {
case .path(let failedPath):
//print("Failed update 2 path: \(failedPath)")
NotificationCenter.default.post(name: Notification.Name("dbFileCreationError"), object: nil, userInfo: nil)
break
default:
//print("Unknown \(error)")
break
}
case .internalServerError(let code, let message, let requestId):
//print("InternalServerError[\(requestId)]: \(code): \(message)")
NotificationCenter.default.post(name: Notification.Name("dbInternalServerError"), object: nil, userInfo: nil)
break
case .badInputError(let message, let requestId):
//print("BadInputError[\(requestId)]: \(message)")
NotificationCenter.default.post(name: Notification.Name("dbBadInputError"), object: nil, userInfo: nil)
break
case .authError(let authError, let requestId):
//print("AuthError[\(requestId)]: \(authError)")
NotificationCenter.default.post(name: Notification.Name("dbAuthError"), object: nil, userInfo: nil)
break
case .rateLimitError(let rateLimitError, let requestId):
//print("RateLimitError[\(requestId)]: \(rateLimitError)")
NotificationCenter.default.post(name: Notification.Name("dbRateLimitError"), object: nil, userInfo: nil)
break
case .httpError(let code, let message, let requestId):
//print("HTTPError[\(requestId)]: \(code): \(message)")
NotificationCenter.default.post(name: Notification.Name("dbHTTPError"), object: nil, userInfo: nil)
break
default:
break
}
}
}
}
你总是可以使用[Objective-C的桥接头(https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html)调入的Objective-C来自Swift的代码。 –
您可能还会看看SwiftyDropbox,这是用于Dropbox API v2的新Swift SDK(当前处于预览状态):https://blogs.dropbox.com/developers/2015/05/try-out-swiftydropbox-the-new- SWIFT-SDK换的Dropbox-API-V2 /。 – smarx