我在ViewController中创建了一个用户配置文件编辑页面。当用户仅编辑文本字段并按下保存按钮时,即使图片相同,它仍会再次上传。我想检查图像是否相同,跳过当前图像的上传。另外解析使用相同的图像文件名,因此按名称检查将不起作用,我不知道还有什么用。有任何想法吗? 这是我的代码:
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")
}
}
}
没有运气
答案 0 :(得分:0)
只需获取已保存的图像数据,并将其与即将保存的图像数据进行比较,如果相同,则不允许它们继续保存,或者您的用例是什么。