Start 2025 on time and up to date. Seamlessly integrate your calendars into Dropbox with these simple steps.

Forum Discussion

rabbigarfinkel's avatar
rabbigarfinkel
Explorer | Level 4
9 years ago

Downloading file with Swiftydropbox

I have successfully installed Swiftydropbox and my app successfully registers with Dropbox.  But I don't understand what to do now if I want to download from a Dropbox. My goal is to download a text file into a URL and then open that URL in a tableview.

 

I think where I'm having trouble understanding the docs is this line:

 

 client.files.download(path: "/test/path/in/Dropbox/account", overwrite: true, destination: destination)

What goes in place of /test/path/in/Dropbox/account?  For instance, how would I get the app to download something from my own account?

 

Thank you,

 

Eli

  • Greg-DB's avatar
    Greg-DB
    9 years ago

    That code doesn't list or display any files. It only downloads a file at "/Documents/RamKolText2.txt".

     

    If you want to get a list of files to display to the user, you can use listFolder and listFolderContinue.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    That path should be the remote path of the file in the connected Dropbox that you want to download. For example, to get a file named "example.txt" in a folder named "Documents", you would supply "/Documents/example.txt".

     

    If you're getting metadata about files from the API, this would be the "pathLower" property of a FileMetadata object.

    • rabbigarfinkel's avatar
      rabbigarfinkel
      Explorer | Level 4

      Thank you.  The problem is that I would not know the filepath of a user's selected file.  In the code below, what line is supposed to trigger the display of the user's files so that the user can tap on a file and return that path to my app?

       

      // Download to URL
              let fileManager = FileManager.default
              let directoryURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
              let destURL = directoryURL.appendingPathComponent("/Documents/RamKolText2.txt")
              let destination: (URL, HTTPURLResponse) -> URL = { temporaryURL, response in
                  return destURL
              }
              client.files.download(path: "/Documents/RamKolText2.txt", overwrite: true, destination: destination)
                  .response { response, error in
                      if let response = response {
                          print(response)
                      } else if let error = error {
                          print(error)
                      }
                  }
                  .progress { progressData in
                      print(progressData)
              }

       

      Thanks! 

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        That code doesn't list or display any files. It only downloads a file at "/Documents/RamKolText2.txt".

         

        If you want to get a list of files to display to the user, you can use listFolder and listFolderContinue.