amazon web services - What are the best practices for user uploads with S3? -


i wondering recommend running user upload system s3. plan on using mongodb storing metadata such uploader, size, etc. how should go storing actual file in s3.

here of ideas, think best? of these examples involve saving metadata mongodb.

1.should store files in bucket?
2. maybe organize them dates (e.g. 6/8/2014/mypicture.png)?
3.should save them in 1 bucket, added string (such d1jdaz9-mypicture.png) avoid duplicates.
4. or should generate long string folder, , store file in folder. (to retain original file name). e.g. sh8sb36zkj391k4dhqk4n5e4ndsqule6/mypicture.png

this depends on how intend use pictures , objects/classes/modules/etc. in code deal retrieving them.

  1. if find wanting things - "all user uploads on particular day" - simple naming convention folders year, month , day along folder @ top level user's unique id solve problem.

  2. if want ensure uniqueness , avoid collisions in bucket, generate unique string too.

however, since you've got mongodb (i'm assuming) handle these queries user uploads date, etc., makes choice of bucket more aesthetic functional.

if you're storing in mongodb key/url, doesn't matter actual structure of bucket is. nevertheless, makes sense still split in coherent way - maybe group user's uploads , give each unique name (either generate unique name or prefix unique prefix file name).

that being said, think there might point when might @ changing how images stored? might move cdn. third party might come cheaper/better product might want try. in case that, storing keys/urls in mongodb not idea since you'll have update every entry.

to make relatively future-proof, suggest give uploads definite structure. opt for:

bucket_name/user_id/yyyy/mm/dd/unique_name.jpg 

your database needs store file name , upload time stamp.

you can introduce middle layer in logic (a new class perhaps or helper function/method) generates url file based on info. way, if change storage method later, need make small change in middle layer (after migrating files of course) , not worry mongodb.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -