THE BORE

General => The Superdeep Borehole => Topic started by: GilloD on February 16, 2010, 09:18:37 PM

Title: SQL/S3 Q for nerdz.
Post by: GilloD on February 16, 2010, 09:18:37 PM
Okay, so I'm working on a new web project that I can't really discuss yet. But here's the gist:

A user can upload a file. This file lands in an AmazonS3 Bucket. Buckets are just like folders. Let me propose a scenario:

User 1 uploads a file called "a.doc"
User 2 uploads a file called "a.doc"

In this instance, User2's file will overwrite User 1's file. The obvious solution is to give these files unique names before we upload them to the S3 server. Because of the way "Buckets" work, we can't create sub-buckets. You can give files names like "/users1/a.doc" and fake it, but it can cause headaches down the line. KISS, yes? So: Unique Names.

The other thing that;s important here is that every file that gets uploaded gets a record written to a local SQL DB- It's just the S3 URL, a primary key ID, the ID of the user that uploaded it and some odds and ends data. We'll use these records to sort and display the files later.

So, I was thinking that the best way to uniquely ID these files would be to have the schema "primaryfileid-filename.ext". But this requires that we write the record, then somehow get the ID back all before the file gets uploaded. guh. And it works on the supposition that the FIle ID will always be the largest ID + 1, which may not be true if you have multiple users concurrently using the system.

Idea 2 is to to just attach a Username AND a random 1-999# of the front like this "username-random-filename.ext". That one makes the most sense, I guess, but it also seems cumbersome.

Any other ideas? Am I overthinking this? Basically I need a way to keep every file as unique as possible from a naming perspective.
Title: Re: SQL/S3 Q for nerdz.
Post by: Powerslave on February 16, 2010, 09:32:49 PM
sqlqslslq q qs qsllqlsqllqsqlqslsqsqslqsllslqqlsqlqsqqslqslqslslslqlssqs ql lqs qlslsssl ls ls slqsqlslq sqs lq slqs lq 3
Title: Re: SQL/S3 Q for nerdz.
Post by: GilloD on February 16, 2010, 09:37:22 PM
sqlqslslq q qs qsllqlsqllqsqlqslsqsqslqsllslqqlsqlqsqqslqslqslslslqlssqs ql lqs qlslsssl ls ls slqsqlslq sqs lq slqs lq 3

What percentage of your 8455 posts are utterly ignorable?
Title: Re: SQL/S3 Q for nerdz.
Post by: Powerslave on February 16, 2010, 09:55:27 PM
sqlqslslq q qs qsllqlsqllqsqlqslsqsqslqsllslqqlsqlqsqqslqslqslslslqlssqs ql lqs qlslsssl ls ls slqsqlslq sqs lq slqs lq 3

What percentage of your 8455 posts are utterly ignorable?

For you it will be a 100% since I'm not really interested in making shitty posts so we have nothing in common :smug
Title: Re: SQL/S3 Q for nerdz.
Post by: Fragamemnon on February 16, 2010, 10:31:54 PM
date/timestamps embedded into the filename wouldn't work? Seems like you could keep the filenames meaningful while stilll maintaining uniqueness, provided that you don't have too much traffic for the amount of granularity you use in your timestamp (second/tenth of second).
Title: Re: SQL/S3 Q for nerdz.
Post by: Bocsius on February 16, 2010, 11:31:47 PM
In theory, appending a timestamp to the filename is good, but then the filenames can become meaningless (given a full replacement, or just way too long otherwise) and are not helpful should you actually need to type it in.

The way I do it when I work on a project that allows for file uploads is sort of a first come, first serve, increment the rest approach. What I mean is I check to see if the filename already exists in the given directory. If not, I save the file as whatever name it is. If the name is already taken, then start monkeying with the filename to keep it unique. (I generally just append a number, starting with 1 and incrementing up as needed.) This way, you preserve the filenames and the meaning behind them, but you do not overwrite anything.
Title: Re: SQL/S3 Q for nerdz.
Post by: Arbys Roast Beef Sandwich on February 16, 2010, 11:46:34 PM
The way I do it when I work on a project that allows for file uploads is sort of a first come, first serve, increment the rest approach. What I mean is I check to see if the filename already exists in the given directory. If not, I save the file as whatever name it is. If the name is already taken, then start monkeying with the filename to keep it unique. (I generally just append a number, starting with 1 and incrementing up as needed.) This way, you preserve the filenames and the meaning behind them, but you do not overwrite anything.

I think this is how ImageShack does it. Smart, simple implementation IMO.
Title: Re: SQL/S3 Q for nerdz.
Post by: GilloD on February 17, 2010, 04:24:43 AM
It's just a gigantic pain the ass to check a list of objects in an S3 bucket. I ended up using "username-rand#-filename"