re-frame-firebase icon indicating copy to clipboard operation
re-frame-firebase copied to clipboard

Added support for Firebase Storage & Firebase Functions

Open wkok opened this issue 4 years ago • 1 comments

Thank you for this library, I find it extremely useful.

Currently you have wrappers for Firebase Authentication, Realtime Database & FireStore

I thought it useful to include basic operations of Firebase Storage and Firebase Functions submitted via this Pull Request.

Storage

re-frame effects are implemented for basic Storage functions put, delete & download-url

Put

Puts a collection of File objects into a Firebase Storage bucket. See: https://firebase.google.com/docs/storage/web/upload-files

Required arguments :path :file

  • :path Path to object in the Storage bucket
  • :file File (https://developer.mozilla.org/en-US/docs/Web/API/File)
  • :bucket If not supplied, will assume the default Firebase allocated bucket
  • :metadata Map of metadata to set on Storage object
  • :on-progress Will be provided with the percentage complete
  • :on-success
  • :on-error

Example FX:

   {:storage/put [{:path "path/to/object"
                   :file File
                   :metadata {:customMetadata {"some-key" "some-value"}}
                   :on-progress #(.log js/console (str "Upload is " % "% complete."))
                   :on-success #(js/alert "Success!")
                   :on-error #(js/alert "Error: " %)}]}

Delete

Deletes a collection of object paths/keys from a Firebase Storage bucket. See: https://firebase.google.com/docs/storage/web/delete-files

Required arguments :path

  • :path Path to object in the Storage bucket
  • :bucket If not supplied, will assume the default Firebase allocated bucket
  • :on-success
  • :on-error

Example FX:

  {:storage/delete [{:path "path/to/object"
                     :on-success #(js/alert "Success!")
                     :on-error #(js/alert "Error: " %)}]}

Download URL

Generates a url with which the browser can download an object from Firebase Storage See: https://firebase.google.com/docs/storage/web/download-files

Required arguments: :path

  • :path Path to object in the Storage bucket
  • :bucket If not supplied, will assume the default Firebase allocated bucket
  • :on-success Will be provided with the download url
  • :on-error

Example FX:

  {:storage/download-url {:path "path/to/object"
                          :on-success #(js/window.open %)
                          :on-error #(js/alert "Error: " %)}}

Functions

re-frame effects are implemented for basic Functions of call

Call

Executes a Callable Firebase Cloud Function See: https://firebase.google.com/docs/functions/callable

Required arguments: :cfn-name :data

  • :cfn-name Cloud Function name
  • :data Map containing request data
  • :on-success Will be called with a clojure Map containing the response data
  • :on-error

Example FX:

  {:functions/call {:cfn-name "my-function-name"
                    :data {:foo "bar"} 
                    :on-success #(js/alert (:foobar %))
                    :on-error #(js/alert "Error: " %)}}

wkok avatar Jul 09 '20 11:07 wkok

What a synchronicity, i was searching for storage in this repo like 5 minutes after your pull request ;) how can i help in getting this merged? would love to use it!

jumski avatar Jul 09 '20 11:07 jumski