【问题标题】:Upload Image to Dropbox using SwiftyDropbox使用 SwiftyDropbox 将图像上传到 Dropbox
【发布时间】:2016-11-07 06:23:04
【问题描述】:

我正在尝试使用 SwiftyDropbox 和 Swift 3.0 将 UIImageView 中的图像上传到 Dropbox。当我按下按钮时,在第一个打印语句之后没有任何反应。我究竟做错了什么。

 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)
})
}


}

【问题讨论】:

  • 您的上传代码在哪里?能否请您在此处添加您的上传代码?
  • Allen,我会放一个打印语句来查看响应语句中返回的内容。所以像 print("response \(response) \(error)").
  • 我认为 client?.files.upload(path: path, mode: .overwrite, autorename: true, clientModified: nil, mute: false, input: fileData!) 是我的上传代码,来自我看到的例子。
  • files.upload方法是上传文件的方法。你能检查你的client 是非空的吗?
  • 它是说当我打印它时我的客户是零。所以它没有保持登录?

标签: ios swift dropbox dropbox-api swiftydropbox


【解决方案1】:

如果您的客户端为 nil,那么您还没有登录。请尝试登录并再次登录。否则它应该可以正常工作。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多