Module storage

Module storage 

Source
Expand description

§Firebase Storage

This module ports core pieces of the Firebase Storage Web SDK to Rust so applications can discover buckets, navigate object paths, and perform common download, metadata, and upload operations using an async reqwest client that works on native and wasm targets.

It provides functionality to interact with Firebase Storage, including uploading and downloading files, managing metadata, and handling storage references.

It includes error handling, configuration options, and integration with Firebase apps.

Porting status: 60% [###### ] (details)

§Features:

  • Connect to Firebase Storage emulator
  • Get storage instance for a Firebase app
  • Register storage component
  • Manage storage references
  • Handle file uploads with progress tracking
  • Upload strings and browser blobs with shared helpers
  • Stream large uploads directly from async readers
  • Stream downloads as native async readers (non-WASM)
  • List files and directories in storage
  • Manage object metadata
  • Comprehensive error handling

§Quick Start Example

use firebase_rs_sdk::app::*;
use firebase_rs_sdk::storage::*;

#[tokio::main]
async fn main() -> StorageResult<()> {
    let options = FirebaseOptions {
        storage_bucket: Some("BUCKET_NAME".into()),
        ..Default::default()
    };

    let app = initialize_app(options, Some(FirebaseAppSettings::default())).await?;

    let storage = get_storage_for_app(Some(app), None).await?;

    let photos = storage
        .root_reference()?
        .child("photos");

    // Upload a photo; small payloads are sent via multipart upload while larger blobs use the resumable API.
    let image_bytes = vec![/* PNG bytes */];
    let mut upload_metadata = UploadMetadata::new().with_content_type("image/png");
    upload_metadata.insert_custom_metadata("uploaded-by", "quickstart");

    let metadata = photos
        .child("welcome.png")
        .upload_bytes(image_bytes, Some(upload_metadata))
        .await?;
    println!(
        "Uploaded {} to bucket {}",
        metadata.name.unwrap_or_default(),
        metadata.bucket.unwrap_or_default()
    );

    // List the directory and stream the first few kilobytes of each item.
    let listing = photos.list_all().await?;
    for object in listing.items {
        let url = object.get_download_url().await?;
        let bytes = object.get_bytes(Some(256 * 1024)).await?;
        println!("{} -> {} bytes", url, bytes.len());
    }

    Ok(())
}

§References to the Firebase JS SDK

Structs§

BackoffConfig
Configuration for exponential backoff when issuing storage requests.
BackoffState
Tracks the evolving backoff state across attempts.
FirebaseStorageImpl
HttpClient
ListOptions
ListResult
Location
ObjectMetadata
PreparedString
RequestInfo
ResponsePayload
ResumableUploadStatus
SetMetadataRequest
StorageError
StorageReference
StreamingResponse
UploadProgress
Progress information emitted while uploading large blobs.
UploadTask
Stateful helper that mirrors the Firebase Web SDK’s resumable upload behaviour.

Enums§

RequestBody
RequestError
StorageErrorCode
StringFormat
Mirrors the Firebase Web SDK string upload formats.
UploadTaskState
Represents the execution state of an UploadTask.

Constants§

DEFAULT_HOST
DEFAULT_MAX_OPERATION_RETRY_TIME_MS
DEFAULT_MAX_UPLOAD_RETRY_TIME_MS
DEFAULT_PROTOCOL
RESUMABLE_UPLOAD_CHUNK_SIZE
STORAGE_TYPE

Traits§

UploadAsyncRead

Functions§

app_deleted
build_list_options
child
connect_storage_emulator
continue_resumable_upload_request
create_resumable_upload_request
delete_object_request
delete_storage_instance
download_bytes_request
download_url_request
get_metadata_request
get_resumable_upload_status_request
get_storage_for_app
internal_error
invalid_argument
invalid_default_bucket
invalid_root_operation
invalid_url
is_retry_status_code
is_url
last_component
list_request
multipart_upload_request
no_default_bucket
no_download_url
parent
parse_list_result
prepare_string_upload
register_storage_component
storage_ref_from_reference
storage_ref_from_storage
unknown_error
unsupported_environment
update_metadata_request

Type Aliases§

ErrorHandler
ResponseHandler
SettableMetadata
StorageByteStream
StorageResult
StreamingDownload
UploadMetadata