代码之家  ›  专栏  ›  技术社区  ›  rustyshackleford

无法使用Swifthydropbox调用“上载”

  •  0
  • rustyshackleford  · 技术社区  · 7 年前

    我刚刚开始iOS开发,我正在使用Dropbox API和SwiftHydroPBox。我试图将文本文件上载到dropbox,但出现以下错误:

    无法使用类型为“(路径:String)”的参数列表调用“upload”

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

    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
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Rashwan L    7 年前

    你不能像以前那样做。在 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)
    }