【问题标题】:Swift : Dropbox image upload fails due to RegEX pattern match failingSwift:由于 RegEX 模式匹配失败,Dropbox 图像上传失败
【发布时间】:2016-02-09 19:45:48
【问题描述】:

我正在使用 SwiftyDropbox API 将图像上传到 Dropbox。我在项目目录中有图像并尝试像这样上传它:

    // Verify user is logged into Dropbox
    if let client = Dropbox.authorizedClient {

        let imagePath : NSString = NSBundle.mainBundle().pathForResource("abc", ofType: "png")!
        print("Path :--> \n", imagePath)
        let url : NSURL = NSURL(string: imagePath as String)!

        client.files.upload(path: "", body: url).response{response, error in


            if let metadata = response {
                print("*** Upload file ****")
                print("Uploaded file name: \(metadata.name)")

                self.delegate?.imageSavedSuccessfully()
            }
            else{
                print(error!)
            }

        }

我得到的错误是(也包括屏幕截图。):

 precondition failed: " must match pattern "\A(?:/.*)\z":

任何提示或指导我做错了什么?先感谢您。

【问题讨论】:

    标签: ios swift dropbox-api


    【解决方案1】:

    对于您的文件上传,您指定了路径"",但它代表根文件夹,而不是文件路径。

    相反,路径应该是您要上传文件的完整路径,包括文件名。例如,要将文件作为“abc.png”上传到 Dropbox 帐户的根目录中,您需要将路径指定为 "/abc.png"

    【讨论】:

    • 呃。我想我在某处读到提到提供"" 会将其上传到根文件夹。但是非常感谢。感谢您的快速回答!
    • 没问题。作为参考,"" 用于表示根文件夹,但仅在被接受为有效值的情况下,例如,将根列为文件夹时。
    • 文件上传功能告诉你使用空字符串作为路径?您可以将详细信息作为新问题发布吗?
    • 我的错。我实际上忘记将文件名附加到参数path 并在日志中说使用空字符串。也许可以更改该日志消息的措辞。简而言之,我做了client.files.upload(path: "/", body : .....) 而不是client.files.upload(path: "/" + fileName , body: .....)
    • 哦,我明白了。似乎我们有一些过于广泛的检查来寻找“/”作为根,试图提供帮助并让开发人员知道使用“”作为根。不过,这在上传文件的情况下没有意义。我们会把它清理干净。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多