How to use the react-native-firebase.storage function in react-native-firebase

To help you get started, we’ve selected a few react-native-firebase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xaphod / LaneChange / app / utils / firebase.js View on Github external
UUIDGenerator.getRandomUUID((uuid) => {
      consolelog(`DEBUG firebase/uploadReport(), uuid=${uuid}`);

      let refName = chosenCity;
      refName = refName.replace(/[^a-z0-9+]+/gi, '');
      if (__DEV__) {
        refName = `${refName}-testing`;
      }
      const firebaseImageRef = firebase.storage().ref(`${refName}-images`).child(`${uuid}.jpg`);
      const uploadTask = firebaseImageRef.putFile(imageURIOnDisk, {
        contentType: 'image/jpeg',
      });

      uploadTask.catch((error) => {
        consolelog('DEBUG firebase/uploadReport: ERROR:');
        consolelog(error);
        reject(error);
      });

      // https://firebase.google.com/docs/storage/web/upload-files
      uploadTask.on('state_changed', (snapshot) => {
        // Observe state change events such as progress, pause, and resume
        // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
        const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
        consolelog('DEBUG firebase/uploadReport: Upload is ' + progress + '% done');
github celo-org / celo-monorepo / packages / mobile / src / utils / LogUploader.ts View on Github external
static async uploadLogsToFirebaseStorage(
    localFilePath: string,
    uploadPath: string,
    uploadFileName: string
  ) {
    try {
      await firebase.auth().signInAnonymously()

      const currentDayUTC = new Date().toISOString().slice(0, 10) // example: 2019-05-10

      const fullUploadPath = `logs/${currentDayUTC}/${uploadPath}/${uploadFileName}`
      Logger.debug(TAG, `uploading local log file ${localFilePath} to ${fullUploadPath}`)

      // Note: when this "await" finishes upload might still be pending, so, if the file gets deleted,
      // the upload will fail.
      await firebase
        .storage()
        .ref(fullUploadPath)
        .putFile(localFilePath)

      Logger.debug(
        `${TAG}/uploadLogsToFirebaseStorage`,
        `Firebase logs from file ${uploadFileName} uploaded successfully`
      )
    } catch (e) {
      Logger.error(
        `${TAG}/uploadLogsToFirebaseStorage`,
        `Failed to upload logs from file ${uploadFileName} to Firebase storage: ` + e
      )
    }
  }
github karanpratapsingh / Proximity / app / utils / firebase.ts View on Github external
import firebase from 'react-native-firebase';
import { generateUUID } from './shared';
import { Asset, StoragePaths, Errors } from '../constants';
import { Platform } from 'react-native';

export const storage = firebase.storage();
export const messaging = firebase.messaging();
export const notifications = firebase.notifications();
export const crashlytics = firebase.crashlytics();

export const initializeFCM = async () => {
  try {
    if (Platform.OS === 'android') {
      const channel = new firebase
        .notifications
        .Android
        .Channel('proximity-channel', 'Notification Channel', firebase.notifications.Android.Importance.Max)
        .setDescription('Proximity Notification Channel')
        .setSound('default');

      notifications.android.createChannel(channel);
    }
github binbytes / react-native-firebase-chat / src / store / user.js View on Github external
async imageUpload() {
    let data = {
      avatarSource: this.avatarSource,
      avatarRef: this.avatarRef
    }
    if (this.fileName !== '') {
      if (this.avatarRef !== '') {
        await firebase
          .storage()
          .ref(this.avatarRef)
          .delete()
      }
      const rImage = await firebase
        .storage()
        .ref('/profilePics/' + getFileName(this.fileName))
        .putFile(this.avatarSource)
      data = {
        avatarSource: rImage.downloadURL,
        avatarRef: rImage.ref
      }
    }
    return data
  }
}
github Bruno-Furtado / fastbuy-app / src / services / FirebaseService.js View on Github external
static uploadImage(path) {
    const id = imageId();
    return firebase.storage().ref(`/products/images/${id}.jpg`).putFile(path);
  }
github xaphod / LaneChange / app / utils / firebase.js View on Github external
snapshot.forEach((doc) => {
    const { image } = doc.data();
    if (image) {
      const photoRef = firebase.storage().refFromURL(image);
      if (photoRef) {
        photoRef.delete()
          .catch((e) => {
            throw e;
          });
      }
    }
    doc.ref.delete()
      .catch((e) => {
        throw e;
      });
  });