Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
App4G
5 years agoHelpful | Level 6
Files.download does not start when number of files in folder is > 1000
I'm having trouble downloading entire folders to a local device via swiftyDropbox.
I am doing the ListFolder and ListFolderContinue (which I observe that it chunks it to ~500 files per ...
- 5 years ago
This post https://stackoverflow.com/a/66227963/14414215 greatly helped in my understanding of how semaphore works and how implementing semaphores (besides using dispatchGroups) is able to properly control the files.download calls.
static func downloadMissingFiles(client: DropboxClient, callingProcess: String) { let fileManager = FileManager.default let localBaseURL = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0].appendingPathComponent("Cloud/Dropbox", isDirectory: true) let semaphore = DispatchSemaphore(value: 1) // insert desired concurrent downloads value here. // Data will be in the form of // key : "/workouts/workout list 1/peye.mrc" // value : "//workouts/workout list 1/peye.mrc=_-_=015ca880b135d01000000020cb26de0" DispatchQueue.global().async { // Wrap the call within an async block for dbFiles in Array(dbFileNameRevDict) { semaphore.wait() // Decrement the semaphore counter let dbFilePathLower = dbFiles.key let dbFileNameRev = dbFiles.value let fullURL = localBaseURL.appendingPathComponent(dbFileNameRev) if fileManager.fileExists(atPath: fullURL.path) { print(" -> FILE EXISTS dbFileNameRev:\(dbFileNameRev)") localFileList.append(dbFileNameRev) semaphore.signal() // Increment semaphore counter } else { let destination : (URL, HTTPURLResponse) -> URL = { temporaryURL, response in return fullURL } client.files.download(path:dbFilePathLower, overwrite: true, destination: destination) .response { response, error in if let (_, url) = response { print("====> DOWNLOADED:\(url.lastPathComponent)") // we've reached here means we've successfully download the file // So we can (release)increment semaphore counter semaphore.signal() } else if let error = error { print(error) } /// This gives a progress of every single file on it's own. Hence, useless // .progress { progressData in // print(progressData) // } } } } } }
App4G
5 years agoHelpful | Level 6
TQ for your message and response.
Is there any way to get the a callback for then when the request is complete?
Greg-DB wrote:You should update your code to only submit one (or a few) of these at a time.
Alternatively, you can use the downloadZip method to download an entire folder as a zip using one request.
What are the options (swift) to submit them one at a time? (That was actually one of my thinking but I've not been able to get this done as 'client.files.download' doesn't return a callback.)
Is there a Response .success in the api?
I also tried to use dispatch group, entering just before calling 'client.files.download' and exiting after.
Thanks for the suggestion to use downloadZip method, users are likely populating and removing files from their folders so this isn't much helpful.
Thank. you
App4G
5 years agoHelpful | Level 6
This post https://stackoverflow.com/a/66227963/14414215 greatly helped in my understanding of how semaphore works and how implementing semaphores (besides using dispatchGroups) is able to properly control the files.download calls.
static func downloadMissingFiles(client: DropboxClient, callingProcess: String) {
let fileManager = FileManager.default
let localBaseURL = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0].appendingPathComponent("Cloud/Dropbox", isDirectory: true)
let semaphore = DispatchSemaphore(value: 1) // insert desired concurrent downloads value here.
// Data will be in the form of
// key : "/workouts/workout list 1/peye.mrc"
// value : "//workouts/workout list 1/peye.mrc=_-_=015ca880b135d01000000020cb26de0"
DispatchQueue.global().async { // Wrap the call within an async block
for dbFiles in Array(dbFileNameRevDict) {
semaphore.wait() // Decrement the semaphore counter
let dbFilePathLower = dbFiles.key
let dbFileNameRev = dbFiles.value
let fullURL = localBaseURL.appendingPathComponent(dbFileNameRev)
if fileManager.fileExists(atPath: fullURL.path) {
print(" -> FILE EXISTS dbFileNameRev:\(dbFileNameRev)")
localFileList.append(dbFileNameRev)
semaphore.signal() // Increment semaphore counter
} else {
let destination : (URL, HTTPURLResponse) -> URL = { temporaryURL, response in
return fullURL
}
client.files.download(path:dbFilePathLower, overwrite: true, destination: destination)
.response { response, error in
if let (_, url) = response {
print("====> DOWNLOADED:\(url.lastPathComponent)")
// we've reached here means we've successfully download the file
// So we can (release)increment semaphore counter
semaphore.signal()
} else if let error = error {
print(error)
}
/// This gives a progress of every single file on it's own. Hence, useless
// .progress { progressData in
// print(progressData)
// }
}
}
}
}
}
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!