RefirebaseRefirebase

upload

Upload a file to Firebase Storage.

Basic usage

By default, upload does not mint a long-lived download URL (which requires an extra round-trip). If you need a URL, pass { downloadUrl: true }.

storage.upload
const result = await db.storage.upload('media/photo.jpg', file);
// result.path, result.byteSize, result.contentType

With download URL

with URL
// Include a long-lived download URL
const result = await db.storage.upload('public/photo.jpg', file, {
  downloadUrl: true,
});
console.log(result.downloadUrl); // https://...

Custom content type

contentType
// Explicitly set MIME type
const result = await db.storage.upload('data/report.pdf', blob, {
  contentType: 'application/pdf',
});

Parameters

ParamTypeDescription
filePath*stringStorage path, e.g. 'avatars/user123.jpg'.
file*BlobFile to upload. For React Native, use uriToBlob first.
options.downloadUrlbooleanInclude a long-lived download URL in the result.(default: false)
options.contentTypestringOverride the MIME type. Defaults to file.type.

Return value

Returns

Promise<StorageUploadResult>

{ path, byteSize, contentType, downloadUrl? }

For React Native

💡
Device files are URIs, not Blobs. Use uriToBlob from refirebase to convert before uploading.