Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
@IBAction func saveFile(_ sender: Any) {
let client = DropboxClientsManager.authorizedClient
let fileData = "testing data example".data(using: String.Encoding.utf8, allowLossyConversion: false)!
let request = client?.files.upload(path: "/test/path/in/Dropbox/account", input: fileData).response { response, error in
if let response = response {
print("The upload response is \(response)")
} else if let error = error {
print("The upload error is \(error)")
}
}
.progress { progressData in
print(progressData)
}
// in case you want to cancel the request
// if someConditionIsSatisfied {
// request.cancel()
print(" View Loaded ")
}Here I uploaded the file using the swift Language. It gave the uploaded response but the file is not there in the dropbox.
I found my mistake! Thank you
Here I am writing some code snippet. I decalared client as global and created a singleton class.
I hope this will help you.
import SwiftyDropbox
var clientDropBox = DropboxClient(accessToken: "Put Your Valid access token here.")
class Dropboxmanager: NSObject {
private init(client:DropboxClient) {
clientDropBox = client
}
static let sharedInstance = Dropboxmanager(client: clientDropBox)
func dropboxSessionAndAuthorizationWithVC(vc:UIViewController) {
DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: vc, openURL:
{ (url) in
UIApplication.shared.openURL(url)
weak var wself = self
OperationQueue.main.addOperation({
})
wself?.downloadFilesInDropBox()
})
}
func getCurrentUserInformation(completion:@escaping (String)-> Void) {
// Get the current user's account info
clientDropBox.users.getCurrentAccount().response(completionHandler: { (response, error) in
if let account = response {
print("Hello \(account.name.givenName)")
completion(account.name.givenName)
} else {
print(error!)
}
})
}
func createFolderInDropBox(){
clientDropBox.files.createFolder(path: "/TempFolder").response { response, error in
if let response = response {
print(response)
weak var wself = self
wself?.uploadFilesInDropBox()
} else if let error = error {
print(error)
}
}
}
func deleteDropBox(){
clientDropBox.files.delete(path: "/TempFolder/File.extension").response(completionHandler: { (response, error) in
weak var wself = self
wself?.uploadFilesInDropBox()
})
}
func getListOfFolder() {
clientDropBox.files.listFolder(path: "").response { (response, error) in
if let result = response {
print("Folder contents:")
for entry in result.entries {
print(entry.name)
}
} else {
print(error!)
}
}
}
func uploadFilesInDropBox(){
let strUrl = "URL_FILE"
let url = URL(fileURLWithPath: strUrl)
let _ = clientDropBox.files.upload(path: "", mode: Files.WriteMode.add, autorename: true, clientModified: Date(), mute: true, input: url).response { response, error in
if let response = response {
print(response)
CoreDataManager.sharedInstance.deleteAllCoredataObjects()
} else if let error = error {
print(error)
}
}
.progress { progressData in
print(progressData)
}
}
func downloadFilesInDropBox(){
// Download to URL
let strUrl = "Destination Url"
let destURL = URL(fileURLWithPath: strUrl)
let destination: (URL, HTTPURLResponse) -> URL = { temporaryURL, response in
return destURL
}
clientDropBox.files.download(path:"/TempFolder/File.extension", 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)
}
}
}
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!