1

I am trying to upload an image in a UIImageView to Dropbox using SwiftyDropbox and Swift 3.0. When I press the button nothing happens after the first print statement. What am I doing wrong.

 import UIKit
 import SwiftyDropbox

 class ViewController: UIViewController {

let client = DropboxClientsManager.authorizedClient

@IBOutlet weak var myPhotoView: UIImageView!


@IBAction func logInAction(_ sender: Any) {
    myButtonPressed()
}

@IBAction func sendPhotoAction(_ sender: Any) {
    print("Button Pressed")

    let fileData = UIImageJPEGRepresentation(myPhotoView.image!, 1.0)
    //let compressedJPGImage = UIImage(data: fileData!)
    let path = "/"
    client?.files.upload(path: path, mode: .overwrite, autorename: true, clientModified: nil, mute: false, input: fileData!).response{ response, error in
        if let _ = response { // to enable use: if let metadata = response {
            print("OK")
        } else {
            print("Error at end")
        }
    }
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


func myButtonPressed(){
    DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: {(url:URL) -> Void in UIApplication.shared.openURL(url)
})
}


}
  • where is your upload code ? can you please ad your upload code here ? – CodeChanger Nov 07 '16 at 06:39
  • Allen, I would put a print statement to see what is returned in the response statement. So something like print("response \\(response) \\(error)"). – user3069232 Nov 07 '16 at 11:41
  • I thought client?.files.upload(path: path, mode: .overwrite, autorename: true, clientModified: nil, mute: false, input: fileData!) was my upload code, from the examples I saw. – Allen Moore Nov 07 '16 at 13:14
  • The `files.upload` method is the method for uploading a file. Can you check your `client` is non-null though? – Greg Nov 07 '16 at 18:29
  • it is saying my client is nil when I am print it. So it is not holding the login? – Allen Moore Nov 07 '16 at 18:50

1 Answers1

0

if your client is nil, then you aren't logged in. Try logging in and doing it again. Otherwise it should work fine.

https://dropbox.github.io/SwiftyDropbox/api-docs/latest/index.html#configure-your-project

Connor24601
  • 63
  • 1
  • 6