1
votes

Is it possible to upload an image to firebase storage with the rest api? I heard that firebase storage have no rest api but google cloud storage have one. Hoe can I achieve this to upload a image in firebase storage using the google cloud storage rest api?

1

1 Answers

3
votes

What you've heard is correct: there is no specific REST API for uploading file to Cloud Storage Firebase. The only option to upload through Firebase is to use one of the SDKs. And the only option for uploading through a REST API is to use the REST API for Cloud Storage.

From the documentation on uploading a file through the REST API comes this example using CURL:

curl -X POST --data-binary @[OBJECT_LOCATION] \
-H "Authorization: Bearer [OAUTH2_TOKEN]" \
-H "Content-Type: [OBJECT_CONTENT_TYPE]" \
"https://storage.googleapis.com/upload/storage/v1/b/[BUCKET_NAME]/o?uploadType=media&name=[OBJECT_NAME]"

A few things to keep in mind when using this REST API to uploading data to Cloud Storage:

  1. You're uploading directly to Cloud Storage, so need to authorize with an OAuth access token, instead of Firebase Authentication.
  2. Uploads through this API bypass the Firebase security rules you've set up for Storage, so you'll want to either do this from a server only, or control access to the bucket at the Google Cloud Storage level.
  3. Firebase will not generate a download URL for uploads through this REST API automatically. If you want a download URL for a file, you can do so from one of the Firebase SDKs after uploading the file.