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! = URL(string: "file://\(filePath)")
//let fileData = try String(contentsOf: fileUrl, encoding: .utf8)
let fileData = try Data(contentsOf: fileUrl)
let request = self.dropboxClient!.files.upload(
path: "/\(fileUrl.lastPathComponent)",
mode: Files.WriteMode.overwrite,
input: fileData
)
.response { response, error in
if let response = response {
print("Upload complete")
} else if let error = error {
print("Error uploading file: \(error)")
}
}
}
Usually one, two or three of the files uploads fine, but the others throw this error:
Error uploading file: [request-id a2c2eca29485a7d10892343e3d3e57c4] API rate limit error - {
reason = {
".tag" = "too_many_write_operations";
};
"retry_after" = 1;
}
My guess is that my for loop is initiating the 4 uploads at the same time in parallel, and for some reason this isn't allowed - is that right? If so, how do I modify my code to get this to work?
There appears to be a method called batchUploadFiles available on the files object, so I'm guessing that's the ticket, but I can't find any documentation on this or figure out how to use it (apologies, I'm an Android dev not experienced with Swift so I'm feeling like a complete noob
). An example would be muchly appreciated. I'm totally stuck, please help!