我正在尝试用SwiftyDropbox下载一个文件,但我的路径有问题。我在mi Dropbox“prueba.txt”中有一个文件:
这是我用来在应用程序中下载的代码。
import UIKit
import SwiftyDropbox
let clientDB = DropboxClientsManager.authorizedClient
class Controller: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: {
(url: URL) -> Void in UIApplication.shared.open(url)
})
let fileManager = FileManager.default
let directoryURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
let destURL = directoryURL.appendingPathComponent("/test.txt")
let destination: (URL, HTTPURLResponse) -> URL = { temporaryURL, response in
return destURL
}
clientDB?.files.download(path: "/prueba.txt", overwrite: true, destination: destination)
.response{ response, error in
if response != nil{
self.cargarDatosCliente()
//print (response)
} else if let error = error{
print (error)
}
}
.progress{ progressData in
print(progressData)
}
}
}我尝试了不同的方法,但总是得到与“路径”相同的问题,总是错误是path/not_found/...我尝试了其他路径,但是相同的问题。你能帮我一下吗?我的错误在哪里?
谢谢!
发布于 2018-10-18 16:35:02
问题是"/prueba.txt“是一个本地文件路径。Dropbox希望你给它一个远程服务器的文件路径。
您可以使用listFolder和listFolderContinue来检索它们。
例如,如果您要检索应用程序或dropbox的根文件夹中的文件路径,请使用:
var path = ""
clientDB?.files.listFolder(path: path).response(completionHandler: { response, error in
if let response = response {
let fileMetadata = response.entries
if response.hasMore {
// Store results found so far
// If there are more entries, you can use `listFolderContinue` to retrieve the rest.
} else {
// You have all information. You can use it to download files.
}
} else if let error = error {
// Handle errors
}
})fileMetadata包含您需要的路径。例如,您可以像这样获取第一个文件的路径:
let path = fileMetadata[0].pathDisplay发布于 2019-11-04 12:05:29
如果您从API获取有关文件的元数据,这将是FileMetadata对象的"pathLower“属性。
client?.files.download(path: fileMetadata.pathLower!, overwrite: true, destination: destination)
.response { response, error in
if let response = response {
print(response)
} else if let error = error {
print(error)
}
}https://stackoverflow.com/questions/51305941
复制相似问题