We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
sathish1995
9 years agoExplorer | Level 3
Uploaded files are not in the Dropbox
@IBAction func saveFile(_ sender: Any) {
let client = DropboxClientsManager.authorizedClient
let fileData = "testing data example".data(using: String.Encoding.utf8, allowLossyConversion: false)!
...
- 9 years ago[Cross-linking for reference: https://stackoverflow.com/questions/43917563/uploaded-files-are-not-in-dropbox ]
Can you share the full output you're getting? Thanks in advance!
kyo
9 years agoExplorer | Level 4
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)
}
}
}About Dropbox API Support & Feedback
Find help with the Dropbox API from 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!