react-native-firebase/docs/modules/storage.md

2.1 KiB

Storage

RNFirebase mimics the Web Firebase SDK Storage, whilst providing some iOS and Android specific functionality.

Uploading files

Simple

firebase.storage()
    .ref('/files/1234')
    .putFile('/path/to/file/1234')
    .then(uploadedFile => {
        //success
    })
    .catch(err => {
        //Error
    });

With metadata

const metadata = {
    contentType: 'image/jpeg'
}
firebase.storage()
    .ref('/files/1234')
    .putFile('/path/to/file/1234', metadata)

Listen to upload state

const unsubscribe = firebase.storage()
                        .ref('/files/1234')
                        .putFile('/path/to/file/1234')
                        .on('state_changed', snapshot => {
                            //Current upload state
                        }, err => {
                            //Error
                            unsubscribe();
                        }, uploadedFile => {
                            //Success
                            unsubscribe();
                        });

Downloading files

Simple

firebase.storage()
    .ref('/files/1234')
    .downloadFile('/path/to/save/file')
    .then(downloadedFile => {
        //success
    })
    .catch(err => {
        //Error
    });

Listen to download state

const unsubscribe = firebase.storage()
                        .ref('/files/1234')
                        .downloadFile('/path/to/save/file')
                        .on('state_changed', snapshot => {
                            //Current download state
                        }, err => {
                            //Error
                            unsubscribe();
                        }, downloadedFile => {
                            //Success
                            unsubscribe();
                        });

TODO

There are a few methods which have not yet been implemented for Storage:

Reference

  • put()
  • putString()

UploadTask

  • cancel()
  • pause()
  • resume()

DownloadTask

  • cancel()
  • pause()
  • resume()