Kyle C
Kyle C

Reputation: 227

How to upload to Firebase Storage on the frontend when Firebase is connected to the backend?

Problem:

I am in the middle of making a web app using Firebase Cloud Functions. I currently have Firebase connected to the backend of my project. However, I am needing to allow the user to upload files that are approximately around 50MB.

Unfortunately, I just found out recently that the max HTTP req size for Firebase Cloud Functions is 10MB. enter image description here

For security purposes, I have security rules(obviously), so I cannot allow anyone to upload anything to Firebase storage or Firestore. Because the user is authenticated on the backend instead of the frontend, I am unable to use Firebase functions for uploading to Firebase storage and Firestore without the security rules being triggered.

What would be some good solutions for this sort of problem when I am wanting to keep Firebase connected to the backend? Thanks.

Upvotes: 0

Views: 684

Answers (2)

Kyle C
Kyle C

Reputation: 227

Problem Solved!

I have solved this problem by creating a custom token on the backend server using Firebase Auth's CreateCustomToken() method. I then pass this token to the client and signed them in using Firebase Auth's SignInWithCustomToken() method.

This has allowed user's to upload files on the frontend to their dedicated folders in Firebase Storage without triggering any security rules!

Upvotes: 5

reiniergs
reiniergs

Reputation: 107

I don't understand why you can allow the customer to upload files directly to the cloud storage. I guess it's because you are not using firebase authentication?? then the rules won't apply??

What I did in the past if you want to give permission to a third party to upload a file, your function returns a signed URL that will temporarily access to upload a file from their client.

Upvotes: 0

Related Questions