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.contentTypeWith 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
| Param | Type | Description |
|---|---|---|
filePath* | string | Storage path, e.g. 'avatars/user123.jpg'. |
file* | Blob | File to upload. For React Native, use uriToBlob first. |
options.downloadUrl | boolean | Include a long-lived download URL in the result.(default: false) |
options.contentType | string | Override 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.