RefirebaseRefirebase

uriToBlob

new

Convert a React Native / Expo file URI to a Blob for storage uploads.

Usage

React Native files are represented as file:// or content:// URIs, not Blob objects.uriToBlob converts them using fetch so they can be passed to db.storage.upload.

uriToBlob with Expo ImagePicker
import { uriToBlob } from 'refirebase';
import * as ImagePicker from 'expo-image-picker';

const result = await ImagePicker.launchImageLibraryAsync({
  mediaTypes: ['images'],
  quality: 0.8,
});

if (!result.canceled) {
  const blob = await uriToBlob(result.assets[0].uri);
  const uploaded = await db.storage.upload('avatars/me.jpg', blob);
  console.log('Uploaded:', uploaded.path);
}

With progress

with useUploadTask
import { uriToBlob } from 'refirebase';
import { useUploadTask } from 'refirebase/react';

const { upload, progress, state } = useUploadTask();

const blob = await uriToBlob(pickerResult.uri);
await upload('uploads/video.mp4', blob, { downloadUrl: true });

Parameters

ParamTypeDescription
uri*stringFile URI from Expo ImagePicker, DocumentPicker, CameraRoll, etc.

Return value

Returns

Promise<Blob>

A Blob ready to be passed to db.storage.upload or db.storage.uploadWithProgress.