Readit News logoReadit News
Posted by u/fuadnafiz98 3 years ago
Ask HN: What is the best way to Upload Images to AWS S3?
I am building a full stack Nodejs, Express.js and React application with a file upload functionality.

What will be the best approach to upload the file?

1. Upload the file from frontend to S3? 2. First upload the file to backend and then upload the file from backend to S3?

What will be the best option? In my opinion the first approach is better as it doesn't require extra load on backend if the file is larger, but I am not sure about the security issues to keep the AWS credentials in the frontend code.

Any suggestions are welcome :)

danenania · 3 years ago
tothrowaway · 3 years ago
I used S3 a few years ago so this might not be as big of a problem now. But when I started using presigned POST requests to upload documents directly to S3 from the client, there were sporadic problems from the US military, some corporations, and many K-12 schools. S3 would be blocked on their end (likely because someone downloaded a malicious file from S3, and a system admin blocked the whole domain without realizing what they were doing).
mr_gibbins · 3 years ago
I don't have a specific best-practice answer but you could invoke a back-end method which fetches the AWS credentials from Secrets Manager (using a baked-in access key), thereby hiding them from the front-end?

Worth taking a look at the AWS WAF (Well-Architected Framework) as this will give you some AWS-approved architecture ideas.

fuadnafiz98 · 3 years ago
Thanks for answering I will definitely check that out
codegeek · 3 years ago
You need to have server side code for sure. The frontend should just send the file to the backend URL to process. The backend should take care of the logic to upload to S3 (and validations etc as needed). Do not store AWS credentials anywhere on the front end.