Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7725833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:02:45+00:00 2026-06-01T05:02:45+00:00

Each time my user signs in, we pull his profile picture from Facebook. This

  • 0

Each time my user signs in, we pull his profile picture from Facebook. This means when he signs in, I need to check if the existing image is the same thing as the new image. Then, if it isn’t, I need to overwrite the existing image. I can probably hack this together, but what’s the optimal way to do this?

Here’s my model:

class UserProfile(models.Model):
    avatar = models.ImageField(upload_to='img/users')

@receiver(pre_update, sender=FacebookBackend)
def update_user_profile(sender, user, response, details, **kwargs):
    profile, created = UserProfile.objects.get_or_create(user=user)

    if "id" in response:
        from urllib2 import urlopen, HTTPError
        from django.template.defaultfilters import slugify
        from django.core.files.base import ContentFile

        try:
            url = "http://graph.facebook.com/%s/picture" \
                % response["id"]
            avatar = urlopen(url+'?type=large', timeout=15)
            profile.avatar.save(slugify(user.id + 'a') + u'.jpg',
                ContentFile(avatar.read()))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:02:48+00:00Added an answer on June 1, 2026 at 5:02 am

    You can get the image from Facebook and the currently stored image, hash the data of both files and compare the hashes. That’s the common way to check whether images are the same. If the hashes are different then you can replace the currently stored image with the image from Facebook.

    You can use import hashlib; hashlib.sha1(data) (or hashlib.md5(data), this is not a security matter but purely for hashing purposes), where data contains the contents of the image file.

    You could also check the filenames but that’s not reliable. It may be unlikely that a user will upload another profile image with the same filename, it’s still possible. If you are renaming the image files in your system then this approach isn’t possible either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create socket connection each time user logs into my application. This means if
I want to find user tweet's count for each month from the time when
I'm using NSDocumentDirectory to save an image each time user may save different different
Hi I am creating a listbox containing 2 text boxes each time a user
My Rails application makes use of Time.zone so that each user can set their
wat i am trying to is, each time user touches screen, i am adding
Can dijit.form.FilteringSelect generate a seperate autocompletion http query each time user enters different value
What would be the most simple solution each time a user presses a certain
i have single php dynamic page that load image each time app user is
Each time a python file is imported that contains a large quantity of static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.