简体   繁体   中英

Can't invoke “upload” using SwiftyDropbox

I just started iOS development and I'm using the Dropbox API with SwiftyDropbox. I'm trying to upload a text file to dropbox but I'm getting the following error:

Cannot invoke 'upload' with an argument list of type '(path: String)'

Here is my code. What am I doing wrong?

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
}

You can´t do it the way that you have done it. In the path filed you need to add the path to where you want to add the file. Then you need to pass the content. Do it like this instead:

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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM