Reputation: 125
I'm creating a web application that stores a lot of pdf documents, i.e., educational content.
I know the fact that it is not a good practice to store pdf files in my database, i.e., MongoDB.
So I'm planning to store pdf files on AWS and other details related to the pdf file like Title, subject, views, ratings, author, etc. on my MongoDB database.
I'm completely new to AWS, I will figure a way out to upload files to AWS using node, but I am not sure how will I link the file to a document(record) in MongoDB.
NOTE: The file should be linked to a particular record in such a way that I'm easily able to retrieve the file on the front-end using a URL or anything like that also these files should not be accessed directly when opening that URL they should only accessible using my website.
Any extra suggestions will be appreciated.
Upvotes: 2
Views: 2525
Reputation: 99
perhaps the best approach i would take is to upload a pdf file with https://www.npmjs.com/package/multer or https://www.npmjs.com/package/formidable to AWS EC2 instance, store the file metadata including AWS S3 object key which can be used to get the object from s3 with AWS SDK for JavaScript. see Working with Amazon S3 Objects
Upvotes: 1
Reputation: 2865
This article shows something pretty similar to what you want to achieve (instead of documents, they work with images).
Use MongoDB (or DynamoDB, which is an AWS service) to store your document metadata and S3 to store the actual document. Flow will look like this:
Note that, in this case, the developer is using a Lambda function to save the metadata. You can use Node.js to implement your Lambda function.
Upvotes: 4
Reputation: 131
Perhaps you can add a field to the mongo record that has the url from S3?
Upvotes: 1