vendredi 6 février 2015

amazon s3 and django - Allow only the users from my website and not the anonymous users

I am using amazon s3 to store uploaded user images. My problems are:



  • If I permit or grantee for me, I cannot upload or download the contents.

  • If I permit or grantee for everyone, all the users and (especially) anonymous users will be able to see the contents, which I don't want.


So, my question is, what do I do so that only the users from my website can upload, download and delete the content?


In that I have conditions that:



  1. Only the users (user1, user2, user3, ...) who are following the user (user0) can download/view the content?

  2. Only the user who uploaded the view can delete the content.


models.py:



def get_upload_file_name(instance, filename):
return "uploaded_files/%s_%s" %(str(time()).replace('.','_'), filename)

PRIVACY = (
('H','Hide'),
('F','Followers'),
('A','All'),
)

class Status(models.Model):
body = models.TextField(max_length=200)
image = models.ImageField(blank=True, null=True, upload_to=get_upload_file_name)
privacy = models.CharField(max_length=1,choices=PRIVACY, default='F')
pub_date = models.DateTimeField(auto_now_add=True, auto_now=False)
user = models.ForeignKey(User)


settings.py:



DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

AWS_ACCESS_KEY_ID = 'AKIAJQWEN46SZLYWFDMMA'

AWS_SECRET_ACCESS_KEY = '2COjFM30gC+rty571E8eNSDYnTdV4cE3aEd1iFTH'

AWS_STORAGE_BUCKET_NAME = 'yesme'

Aucun commentaire:

Enregistrer un commentaire