gpt4 book ai didi

swift - 无法使用 SwiftyDropbox 调用 "upload"

转载 作者:行者123 更新时间:2023-11-28 15:16:35 25 4
gpt4 key购买 nike

我刚刚开始 iOS 开发,我将 Dropbox API 与 SwiftyDropbox 结合使用。我正在尝试将文本文件上传到保管箱,但出现以下错误:

无法使用“(路径:字符串)”类型的参数列表调用“上传”

这是我的代码。我做错了什么?

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if let authResult = DropboxClientsManager.handleRedirectURL(url) {
switch authResult {
case .success:
print("Logged into Dropbox successfully.")
case .cancel:
print("Authorization canceled.")
case .error(_, let description):
print("Error: \(description)")


}

let client = DropboxClientsManager.authorizedClient

client.files.upload(path: "/hello.txt").response { response, error in
if let metadata = response {
println("Uploaded file name: \(metadata.name)")
println("Uploaded file revision: \(metadata.rev)")

let client = DropboxClientsManager.authorizedClient
client?.files.createFolderV2(path: "/Auction_Upload").response { response, error in
if let response = response {
print(response)
} else if let error = error {
print(error)
}
}
}
return true
}

最佳答案

你不能按照你已经完成的方式去做。在 path 文件中,您需要将路径添加到要添加文件的位置。然后你需要传递内容。改为这样做:

let client = DropboxClientsManager.authorizedClient
let fileData = "Some test text to upload".data(using: String.Encoding.utf8, allowLossyConversion: false)!

let request = client?.files.upload(path: "/test/path/in/Dropbox/account", input: fileData)
.response { response, error in
if let response = response {
print(response)
} else if let error = error {
print(error)
}
}
.progress { progressData in
print(progressData)
}

关于swift - 无法使用 SwiftyDropbox 调用 "upload",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46740450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com