Lukman Ahmed
Lukman Ahmed

Reputation: 81

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

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.

Upvotes: 8

Views: 7386

Answers (2)

WestMountain
WestMountain

Reputation: 625

Frontend, say you have 1000 users, all upload via server, your server will have to do very heavy work. Just let the client do the upload

Upvotes: 0

lgdestro
lgdestro

Reputation: 365

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

Upvotes: 13

Related Questions