We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
ncljames
6 years agoHelpful | Level 5
SwiftDropbox too many write operations when writing 4 files
Hi there, I'm using the SwiftyDropbox library to upload files to Dropbox in an iOS app (Swift). I have a loop where I initiate uploads for 4 files:
for filePath in filePaths {
let fileUrl: URL!...
- 6 years ago
Thanks I didn't think to look at the test cases! For future reference for other users looking for the same, here's the version of my Swift code adapted from the test that works:
var filesCommitInfo = [URL : Files.CommitInfo]() for filePath in filePaths { let fileUrl: URL! = URL(string: "file://\(filePath)") let uploadToPath = "/\(fileUrl.lastPathComponent)" filesCommitInfo[fileUrl] = Files.CommitInfo(path: uploadToPath, mode: Files.WriteMode.overwrite) } self.dropboxClient!.files.batchUploadFiles( fileUrlsToCommitInfo: filesCommitInfo, responseBlock: { (uploadResults: [URL: Files.UploadSessionFinishBatchResultEntry]?,
finishBatchRequestError: CallError<Async.PollError>?,
fileUrlsToRequestErrors: [URL: CallError<Async.PollError>]) -> Void in if let uploadResults = uploadResults { for (clientSideFileUrl, result) in uploadResults { switch(result) { case .success(let metadata): let dropboxFilePath = metadata.pathDisplay! print("Upload \(clientSideFileUrl.absoluteString) to \(dropboxFilePath) succeeded") case .failure(let error): print("Upload \(clientSideFileUrl.absoluteString) failed: \(error)") } } } else if let finishBatchRequestError = finishBatchRequestError { print("Error uploading file: possible error on Dropbox server: \(finishBatchRequestError)") } else if fileUrlsToRequestErrors.count > 0 { print("Error uploading file: \(fileUrlsToRequestErrors)") } })PS Greg I've been browsing the forums lately and you seem to be everywhere, answering people's questions with unlimited patience and kindness. Just wanted to say you're a superstar, thanks
ncljames
6 years agoHelpful | Level 5
Thanks I didn't think to look at the test cases! For future reference for other users looking for the same, here's the version of my Swift code adapted from the test that works:
var filesCommitInfo = [URL : Files.CommitInfo]() for filePath in filePaths { let fileUrl: URL! = URL(string: "file://\(filePath)") let uploadToPath = "/\(fileUrl.lastPathComponent)" filesCommitInfo[fileUrl] = Files.CommitInfo(path: uploadToPath, mode: Files.WriteMode.overwrite) } self.dropboxClient!.files.batchUploadFiles( fileUrlsToCommitInfo: filesCommitInfo, responseBlock: { (uploadResults: [URL: Files.UploadSessionFinishBatchResultEntry]?,
finishBatchRequestError: CallError<Async.PollError>?,
fileUrlsToRequestErrors: [URL: CallError<Async.PollError>]) -> Void in if let uploadResults = uploadResults { for (clientSideFileUrl, result) in uploadResults { switch(result) { case .success(let metadata): let dropboxFilePath = metadata.pathDisplay! print("Upload \(clientSideFileUrl.absoluteString) to \(dropboxFilePath) succeeded") case .failure(let error): print("Upload \(clientSideFileUrl.absoluteString) failed: \(error)") } } } else if let finishBatchRequestError = finishBatchRequestError { print("Error uploading file: possible error on Dropbox server: \(finishBatchRequestError)") } else if fileUrlsToRequestErrors.count > 0 { print("Error uploading file: \(fileUrlsToRequestErrors)") } })
PS Greg I've been browsing the forums lately and you seem to be everywhere, answering people's questions with unlimited patience and kindness. Just wanted to say you're a superstar, thanks
Greg-DB
Dropbox Community Moderator
6 years agoThanks for the kind words, and for sharing your code for others!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 13 hours ago
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 or Facebook.
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!