NodeJS File Upload to Amazon S3 Store Mapping to Database

743 views Asked by At

Im looking at Knox S3 library. In my web app, users are allowed to upload files. Im thinking of using Amazon S3.

In Knox, how to map the file uploaded to the user? Let say I want to know the files that a user uploaded. This will be stored in MongoDB.

Just an idea.

1

There are 1 answers

0
dcro On BEST ANSWER

To figure out what data was uploaded by a specific user, you have two options:

  1. Use an external data store (MongoDB or any other database) and record the relation between the uploaded object on S3 (it's key) and the user. This data recording would be done by your app logic when a new object is uploaded to S3.

  2. Upload the data on S3 under a common prefix (e.g. all files uploaded by a user would be placed in /<user-id>/file.ext) and do a LIST request on the bucket to find all the keys under that prefix.

Usually the first option works best, especially if you need to record multiple relations between your S3 objects and other entities.

These scenarios are not specific to using Knox as an S3 client. They apply independent of the programming language or S3 library.