1
我在ViewController中创建了一个用户配置文件编辑页面。当用户只编辑文本字段并点击保存按钮,即使图片是相同的,它仍然会重新上传。我想检查图像是否相同,跳过当前图像的上传。此外,解析使用相同的图像文件名称,所以按名称检查将无法正常工作,我不知道还有什么其他用途。有任何想法吗? 这里是我的代码:在Swift中避免重复的图片上传文件到Parse.com
let imageUploadData = UIImageJPEGRepresentation(imageUpload.image!, 1)
if (imageUploadData != nil) {
//Here what I tried:
if (currentImage.image != imageUploadData) {
print("Image will be uploaded")
let imageFileObject = PFFile(data: imageUploadData!)
myUser.setObject(imageFileObject!, forKey: "license_image")
}else {
print("Image is the same, skipping upload")
}
}
myUser.saveInBackgroundWithBlock {(success: Bool, error:NSError?) -> Void in
self.clearAllNotice() //Clear activity indicator
if (error != nil) {
print("...")
}
if (success) {
print("Saving")
}
我有什么企图,下面
let userImageFile = PFUser.currentUser()?.objectForKey("license_image") as! PFFile
userImageFile.getDataInBackgroundWithBlock {(imageData: NSData?, error: NSError?) -> Void in
if (error == nil) {
let image = UIImage(data:imageData!)
if image == self.imageUpload.image {
print("image is the same")
}
else {
print("image not the same")
}
}
}
我也试过这个在评论中提到:
let userImageFile = PFUser.currentUser()?.objectForKey("license_image") as! PFFile
userImageFile.getDataInBackgroundWithBlock {(imageData: NSData?, error: NSError?) -> Void in
if (error == nil) {
let image = UIImage(data:imageData!)
let imageFileObject = PFFile(data: imageUploadData!)
if ((image?.isEqual(imageFileObject)) != nil){
print("image is the same")
}
else {
print("image not the same")
}
}
}
没有运气
试过,没有工作 –
我现在解决了这个问题,我把任务分成了不同的按钮 –