'da Parse.com'a çift görüntü yükleme dosyasından kaçınmak için ViewController'da bir kullanıcı profili düzenleme sayfası oluşturdum. Kullanıcı sadece metin alanlarını düzenlediğinde ve resim aynı olsa bile kaydet düğmesine basarsa, yine de tekrar yükleyecektir. Resmin aynı olup olmadığını kontrol etmek istiyorum, geçerli resmin yüklenmesini atla. Ayrıca ayrıştırmak aynı görüntü dosyası adını kullanır, böylece isminin kontrol edilmesi işe yaramaz, başka ne kullanacağımı bilmiyorum. Herhangi bir fikir?Swift
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")
}
Denedim Ne, ben de bu çalıştı
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")
}
}
}
Aşağıdaki yorum belirtildiği:
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")
}
}
}
Hayır şans
bunu denedi, işe yaramadı –
Şu an için sorunu çözdüm, görevi farklı düğmelere ayırdım –