shotvibe / shotvibe-web

ShotVibe REST API webservice
1 stars 0 forks source link

Add User avatars #6

Closed benny-shotvibe closed 11 years ago

benny-shotvibe commented 11 years ago

This is a big task and can be broken down into the model and view components

benny-shotvibe commented 11 years ago

We need to add a new field to the User model

benny-shotvibe commented 11 years ago

I am thinking maybe we should use Amazon S3 to store avatar image files. It would be a good test to see if S3 would be appropriate later for storing also all photos.

prudnikov commented 11 years ago

So, should I use S3 to store avatars?

benny-shotvibe commented 11 years ago

A new field needs to be added to the User model:

avatar_file = models.CharField(max_length=128)

Avatars will be stored in S3.

The actual bucket names should be stored in a setting:

AVATAR_S3_BUCKETS = ('shotvibe-avatars-01', 'shotvibe-avatars-02')

Also the AWS S3 credentials should be stored in an appropriate setting

When a user uploads an avatar image:

  1. The server should resize it down to an appropriate size if necessary
  2. The server should select a random bucket name from settings.AVATAR_S3_BUCKETS
  3. The server should generate a file name in the format: user-avatar-{User.id}-{timestamp}.jpg
  4. The server should upload the file to S3
  5. The server should set the User.avatar_file field to a value: s3:{bucket_name}:{filename.jpg}

The User.get_avatar_url method should me modified to return a string in the format:

https://{bucketname}.s3.amazonaws.com/{filename.jpg}
benny-shotvibe commented 11 years ago

The view for uploading a user avatar should be added to photos_api and be at:

PUT /users/{uid}/avatar/

It should be similar to the PhotoUpload class view, and can use the existing PhotoUploadParser

prudnikov commented 11 years ago

Store user's avatars in different buckets. Scale them to 128x128 px. Use the same format to store information about the location as for images such as 's3:bucketname:filename', 'gae:blah:filename' Define settings AVATAR_S3_BUCKETS = ('shotvibe-avatars-01', 'shotvibe-avatars-02') Filenames template user-avatar-{User.id}-{timestamp}.jpg

prudnikov commented 11 years ago

Since user can upload avatars only for himself we don't need to use user_id in URL. Use PUT /users/avatar/.

prudnikov commented 11 years ago

Required to run

`python manage.py migrate phone_auth`

on every server. This is not required to run unittest.