Ios 如何使用SwiftHydroPBOX下载文件?路径错误
我正在尝试使用SwiftHydropbox下载一个文件,但路径有问题。我在mi Dropbox“prueba.txt”中有一个文件: 这是我用来在我的应用程序中下载的代码Ios 如何使用SwiftHydroPBOX下载文件?路径错误,ios,swift,swiftydropbox,Ios,Swift,Swiftydropbox,我正在尝试使用SwiftHydropbox下载一个文件,但路径有问题。我在mi Dropbox“prueba.txt”中有一个文件: 这是我用来在我的应用程序中下载的代码 import UIKit import SwiftyDropbox let clientDB = DropboxClientsManager.authorizedClient class Controller: UIViewController { override func viewDidLoad() { s
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\u found/…
我尝试了其他的方法,但也是同样的问题。
你能帮我吗?我的错在哪里
谢谢 问题在于“/prueba.txt”是一个本地文件路径。Dropbox希望您为其远程服务器提供一个文件路径
您可以使用和检索这些
例如,如果要检索应用程序或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
如果您从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)
}
}