Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hi guys, just some issues i'm having integrating dropbox into my iOS app. Basically i have it working kind of. I can upload a voice recording into text, into my dropbox folder via the API. The only issue i'm havng is that it uploads multiple files witht the same converted speech to text anyhwere from 3 - 20+ exact copies depending on how long the recording is done for even though there is a 10 second timer before being redirected to the dropbox authorisation. I also don't get the authResult printed in my console stating "Success User logged into DropboxClientsManager" I think the problem is that there is a loop going on whilst recording, so i can never upload only 1 file.
I'll be happy to help with any issues you're having with the Dropbox API, but I'll need some more information. Please reply with:
Xcode version 12.1
@objc func handleTimer() {
lightbulbImage.image = UIImage(named: "litBulb")
playSound()
let tap = UITapGestureRecognizer(target: self, action: #selector(stop))
lightbulbImage.addGestureRecognizer(tap)
lightbulbImage.isUserInteractionEnabled = true
NRSpeechToText.shared.startRecording {(result: String?, isFinal: Bool, error: Error?) in
if error == nil {
if let convertedSpeech = result {
self.speech.append(convertedSpeech)
self.text = self.speech[self.speech.count - 1]
print("This is the speech : \(self.text)")
self.timer = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(self.recordCountdown), userInfo: nil, repeats: false)
}
} else {
print("Could not retrieve recording")
}
}
}
@objc func recordCountdown() {
stop()
DropboxClientsManager.authorizeFromController(UIApplication.shared,
controller: self,
openURL: { (url: URL) -> Void in
UIApplication.shared.openURL(url)
})
self.client.files.createFolderV2(path: "/test/path/in/Dropbox/account").response { response, error in
if let response = response {
print(response)
} else if let error = error {
print(error)
}
}
let fileData = text.data(using: String.Encoding.utf8, allowLossyConversion: false)!
let request = self.client.files.upload(path: "/test/path/in/Dropbox/account", mode: .add, autorename: true, clientModified: nil, mute: false, input: fileData)
.response { response, error in
if let response = response {
print(response)
} else if let error = error {
print("This is the error: \(error)")
}
}
.progress { progressData in
print("This is Progress Data: \(progressData)")
}
// request.cancel()
}
}
Appdelegate code
import UIKit
import SwiftyDropbox
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let constant = Constants()
DropboxClientsManager.setupWithAppKey(constant.MyAPIKey)
return true
}
// MARK: UISceneSession Lifecycle
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let oauthCompletion: DropboxOAuthCompletion = {
if let authResult = $0 {
switch authResult {
case .success:
print("Success! User is logged into DropboxClientsManager.")
case .cancel:
print("Authorization flow was manually canceled by user!")
case .error(_, let description):
print("Error: \(String(describing: description))")
}
}
}
let canHandleUrl = DropboxClientsManager.handleRedirectURL(url, completion: oauthCompletion)
return canHandleUrl
}
}
console:
This is the speech : Testing
This is the speech : Testing one
This is the speech : Testing 12
This is the speech : Testing 123
This is the speech : Testing 123
This is the speech : Testing 123
{
"client_modified" = "2020-10-30T15:51:55Z";
"content_hash" = aa10070a4e571b204bbdf6de20978f0f0c7710516dfd9b2721975b6ffcc693dc;
id = "id:mmEtRfr7QekAAAAAAAACSA";
"is_downloadable" = 1;
name = "account (17)";
"path_display" = "/test/path/in/Dropbox/account (17)";
"path_lower" = "/test/path/in/dropbox/account (17)";
rev = 015b2e5604761d400000001fea52f50;
"server_modified" = "2020-10-30T15:51:56Z";
size = 4;
}
This is Progress Data: <NSProgress: 0x6000014f8500> : Parent: 0x0 (portion: 0) / Fraction completed: 1.0000 / Completed: 4 of 4
{
"client_modified" = "2020-10-30T15:51:56Z";
"content_hash" = aa10070a4e571b204bbdf6de20978f0f0c7710516dfd9b2721975b6ffcc693dc;
id = "id:mmEtRfr7QekAAAAAAAACSQ";
"is_downloadable" = 1;
name = "account (18)";
"path_display" = "/test/path/in/Dropbox/account (18)";
"path_lower" = "/test/path/in/dropbox/account (18)";
rev = 015b2e560542a6a00000001fea52f50;
"server_modified" = "2020-10-30T15:51:56Z";
size = 4;
}
This is Progress Data: <NSProgress: 0x6000014e9a40> : Parent: 0x0 (portion: 0) / Fraction completed: 1.0000 / Completed: 4 of 4
{
"client_modified" = "2020-10-30T15:51:57Z";
"content_hash" = aa10070a4e571b204bbdf6de20978f0f0c7710516dfd9b2721975b6ffcc693dc;
id = "id:mmEtRfr7QekAAAAAAAACSg";
"is_downloadable" = 1;
name = "account (19)";
"path_display" = "/test/path/in/Dropbox/account (19)";
"path_lower" = "/test/path/in/dropbox/account (19)";
rev = 015b2e560616de700000001fea52f50;
"server_modified" = "2020-10-30T15:51:57Z";
size = 4;
}
{
"client_modified" = "2020-10-30T15:51:58Z";
"content_hash" = aa10070a4e571b204bbdf6de20978f0f0c7710516dfd9b2721975b6ffcc693dc;
id = "id:mmEtRfr7QekAAAAAAAACSw";
"is_downloadable" = 1;
name = "account (20)";
"path_display" = "/test/path/in/Dropbox/account (20)";
"path_lower" = "/test/path/in/dropbox/account (20)";
rev = 015b2e5606f381100000001fea52f50;
"server_modified" = "2020-10-30T15:51:58Z";
size = 4;
}
{
"client_modified" = "2020-10-30T15:51:59Z";
"content_hash" = aa10070a4e571b204bbdf6de20978f0f0c7710516dfd9b2721975b6ffcc693dc;
id = "id:mmEtRfr7QekAAAAAAAACTA";
"is_downloadable" = 1;
name = "account (21)";
"path_display" = "/test/path/in/Dropbox/account (21)";
"path_lower" = "/test/path/in/dropbox/account (21)";
rev = 015b2e5607b03ce00000001fea52f50;
"server_modified" = "2020-10-30T15:51:59Z";
size = 4;
}
{
"client_modified" = "2020-10-30T15:52:00Z";
"content_hash" = aa10070a4e571b204bbdf6de20978f0f0c7710516dfd9b2721975b6ffcc693dc;
id = "id:mmEtRfr7QekAAAAAAAACTQ";
"is_downloadable" = 1;
name = "account (22)";
"path_display" = "/test/path/in/Dropbox/account (22)";
"path_lower" = "/test/path/in/dropbox/account (22)";
rev = 015b2e560919eec00000001fea52f50;
"server_modified" = "2020-10-30T15:52:00Z";
size = 4;
}
2020-10-30 15:52:04.981579+0000 Kangae[6887:292358] -canOpenURL: failed for URL: "dbapi-2://1/connect?k=apikeygoeshere&s=" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
2020-10-30 15:52:04.982475+0000 Kangae[6887:292358] -canOpenURL: failed for URL: "dbapi-8-emm://1/connect?k=apikeygoeshere&s=" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
2020-10-30 15:52:04.984412+0000 Kangae[6887:292358] [Presentation] Attempt to present <SwiftyDropbox.MobileSafariViewController: 0x7f85a6837a00> on <Kangae.ViewController: 0x7f85a6608760> (from <Kangae.ViewController: 0x7f85a6608760>) whose view is not in the window hierarchy.
This is Progress Data: <NSProgress: 0x6000014e9c20> : Parent: 0x0 (portion: 0) / Fraction completed: 1.0000 / Completed: 4 of 4
2020-10-30 15:52:05.155551+0000 Kangae[6887:292358] -canOpenURL: failed for URL: "dbapi-2://1/connect?k=apikeygoeshere&s=" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
2020-10-30 15:52:05.156548+0000 Kangae[6887:292358] -canOpenURL: failed for URL: "dbapi-8-emm://1/connect?k=apikeygoeshere&s=" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
2020-10-30 15:52:05.157982+0000 Kangae[6887:292358] [Presentation] Attempt to present <SwiftyDropbox.MobileSafariViewController: 0x7f85a704d400> on <Kangae.ViewController: 0x7f85a6608760> (from <Kangae.ViewController: 0x7f85a6608760>) whose view is not in the window hierarchy.
This is Progress Data: <NSProgress: 0x6000014f95e0> : Parent: 0x0 (portion: 0) / Fraction completed: 1.0000 / Completed: 4 of 4
API route error - {
".tag" = path;
path = {
".tag" = conflict;
conflict = {
".tag" = folder;
};
};
}
API route error - {
".tag" = path;
path = {
".tag" = conflict;
conflict = {
".tag" = folder;
};
};
}
{
"client_modified" = "2020-10-30T15:52:05Z";
"content_hash" = aa10070a4e571b204bbdf6de20978f0f0c7710516dfd9b2721975b6ffcc693dc;
id = "id:mmEtRfr7QekAAAAAAAACTg";
"is_downloadable" = 1;
name = "account (23)";
"path_display" = "/test/path/in/Dropbox/account (23)";
"path_lower" = "/test/path/in/dropbox/account (23)";
rev = 015b2e560dfb91500000001fea52f50;
"server_modified" = "2020-10-30T15:52:06Z";
size = 4;
}
So if I understand correctly, this code is producing multiple copies of files in Dropbox, when you only want it to make one.
Looking through the code, there are a few things to note:
So, it looks like this code is working as written. If you only want to perform one upload, you'll need to update your code to only call that method once. (It may also be helpful to use the debugger to step through the code to see what's happening.) The actual issue here isn't really a matter of the Dropbox API though, and is more a matter of how you structure your code, so I can't offer more help in that regard.
Thanks for your response.
I don't use a button to start the recording. The way my App works it automatically starts recording after 2 seconds and stops recording after 10 seconds. in which it takes that converted speech to string onto the dropbox. the main issue is, even if i say one word into the mic it will append onto the current string multiple times. e.g. if i say "ok" once it will print,
ok
ok
ok
everything i say after that will append onto the string after that
I think the issue is the NRSpeechToText framework that i imported. No matter what i try to do it will always upload multiple textdocuments. I may have to use Apple's speech framework instead for better funtionality.
Hi there!
If you need more help you can view your support options (expected response time for a 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!