Is it better to upload a file to an s3 bucket on the front end or backend?

Viewed 1988

I am creating a web app where there is an option for authenticated users to upload pictures. I am confused as to whether its better to do it on the front end or backend. I have already implemented it on the front end but I had to include my "accessKeyId" and "secretKey". I don't know if this compromises my security. I am using cloud functions for my back end. If anyone can help me with best practices in relation to this I will be very grateful.

1 Answers

You can generate pre-signed urls from your backend, then your frontend can upload files safely directly into S3 without exposing your credentials.

Take a look into the documentation here.

Also, this article points out some of the advantages of that strategy:

  1. You can still allow only authenticated users to get access to presigned urls
  2. You can set expiration time for the generated presigned urls
  3. You save bandwidth, memory processing and upload time by avoiding your files to pass through your backend function
Related