How to link S3 URL to MongoDB in Node.js? How to link S3 URL to MongoDB in Node.js? mongoose mongoose

How to link S3 URL to MongoDB in Node.js?


The url will be your s3 bucket url + the file name. file name(s) will be in the req.files object.

As mentioned in this Reddit post: https://www.reddit.com/r/node/comments/98azig/how_do_i_get_the_uploaded_files_url_on_aws_when/


After uploading to the S3 bucket, should be returned the data, where you can find a "Location". It will be your file URL.

Or you can create a URL manually on your side.

const url = `${BUCKET_URL}/${YOUR_KEY_FROM_UPLOAD_FUNCTION}`;

"YOUR_KEY_FROM_UPLOAD_FUNCTION" can also include the album name.

Examples:

YOUR_KEY_FROM_UPLOAD_FUNCTION : /users/ee44e698-73cd-4fe8-99e0-f82dd4ac221b.png BUCKET_URL:https://s3.amazonaws.com/YOUR_BUCKET_NAME