Topic: Amazon S3 Filenames..

Hey All,

I've just setup my amazon s3 account, I was wondering..

How can I let my users upload their files (thousands of them) and allow them to maintain the same filename, given that s3 doesn't support folders?

The obvious problem is a ton of files with their own names is firstly unorganised, and secondly the common names will quickly be taken up, like brochure.pdf.

I've been thinking of compromising with {account_id}-{asset_id}-{rand}-{filename}.{ext} as when users download the files, they'll want a recognisable name.

So for exmaple, as account number 2, uploading a new asset which happens to be given an id of 105, with a file called brochure.pdf it would become:

2-105-9382-brochure.pdf and would be accessible at … ochure.pdf

Just wondering if there is a better trick for doing this?


PS: The account_id is in there just for organisation, the rand is in there so if people replace a file with another of the same name, it doesn't get cached. Still id like to hear any other ways of doing this.

Last edited by MatthewKing (2008-02-05 08:47:49)

Re: Amazon S3 Filenames..

You're over-engineering the problem. You would just have a folder structure and deal with the naming in your database.

id uuid folder_id human_name
#id is just the pk, uuid is what you upload it to s3 as, the folder_id is what folder its in, and the human_name is what your user wanted to call it

id name
#just a pk and a name that your user wants to give it

Use UUIDs instead of random numbers. You will NEVER have a file with the same name.

You can also (maybe have to) extend the files table to include file-type information so if your users upload a PDF they get it back as a PDF. Creation and modification times would be nice to have as well.

Re: Amazon S3 Filenames..

Wouldn't that mean the file would still be downloaded as some random name, and not actually the name that the user wanted?

They download it directly from s3..

Re: Amazon S3 Filenames..

Ooh right. I missed that part. I did a bit of work like this at an internship and at my current position. Let me noodle it for a bit, I find database<->filesystem problems like this interesting for some sick reason.