Swift : 由于 RegEX 模式匹配失败,Dropbox 图片上传失败
Swift : Dropbox image upload fails due to RegEX pattern match failing
我正在使用 SwiftyDropbox API 将图像上传到保管箱。我在项目目录中有图像并尝试像这样上传它:
// 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":
任何提示或指导我做错了什么?先感谢您。
对于文件上传,您要指定路径 ""
,但它代表根文件夹,而不是文件路径。
相反,路径应该是您要上传文件的完整路径,包括文件名。例如,要将文件作为 "abc.png" 上传到 Dropbox 帐户的根目录中,您需要将路径指定为 "/abc.png"
.
我正在使用 SwiftyDropbox API 将图像上传到保管箱。我在项目目录中有图像并尝试像这样上传它:
// 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":
任何提示或指导我做错了什么?先感谢您。
对于文件上传,您要指定路径 ""
,但它代表根文件夹,而不是文件路径。
相反,路径应该是您要上传文件的完整路径,包括文件名。例如,要将文件作为 "abc.png" 上传到 Dropbox 帐户的根目录中,您需要将路径指定为 "/abc.png"
.