Storage

storage.uploadFile(pathOrRef, file, metadata)
Function

Uploads a file to cloud storage.

When executed within a call effect, redux-saga will "resolve" the returned UploadTask into an UploadTaskSnapshot and directly return that instead. You might want to consider not using the call effect creator when using this method.

More information in issue #177.

Arguments

TypeDescription
pathOrRef
Optional

String or Firebase Storage Reference

The path or reference of the file in the bucket.

file
Optional

Blob, File or Uint8Array

The file to upload at the specified path.

metadata
Optional

UploadMetadata

Metadata to attach to the file.

Output

An UploadTask object.

Example

function* uploadFile(action) {
  const task = rsf.storage.uploadFile(action.path, action.file);

  const channel = eventChannel(emit => task.on('state_changed', emit));

  yield takeEvery(channel, ...);

  // Wait for upload to complete
  yield task

  // Do something on complete
}

storage.uploadString(pathOrRef, string, format, metadata)
Function

Use this to upload a raw, base64, base64url, or data_url encoded string to Cloud Storage.

Arguments

TypeDescription
pathOrRef
Optional

String or Firebase Storage Reference

The path or reference of the file in the bucket.

string
Optional

String

The content to upload.

format
Optional

String

Available options are: base64, base64url, or data_url.

metadata
Optional

UploadMetadata

Metadata to attach to the file.

Output

An UploadTask object.

Example

function* uploadString(action) {
  const task = yield call(rsf.storage.uploadString, action.path, action.fileData, 'base64');

  const channel = eventChannel(emit => task.on('state_changed', emit));

  yield takeEvery(channel, ...);

  // Wait for upload to complete
  yield task

  // Do something on complete
}

storage.getDownloadURL(pathOrRef)
Generator

Returns a download url for the file at the specified path.

Arguments

TypeDescription
pathOrRef
Optional

String or Firebase Storage Reference

The path or reference of the file in the bucket.

Output

An URL as a string.

Example

function* downloadFile(action) {
  const url = yield call(rsf.storage.getDownloadURL, action.path);

  yield call(fetch, url, ...);
}

storage.getFileMetadata(pathOrRef)
Generator

Returns the metadata attached to a file.

Arguments

TypeDescription
pathOrRef
Optional

String or Firebase Storage Reference

The path or reference of the file in the bucket.

Output

A FullMetadata object.

Example

function* metadata(action) {
  const metadata = yield call(rsf.storage.getFileMetadata, action.path);
  return metadata;
}

storage.updateFileMetadata(pathOrRef, newMetadata)
Generator

Updates the metadata for a file.

Arguments

TypeDescription
pathOrRef
Optional

String or Firebase Storage Reference

The path or reference of the file in the bucket.

newMetadata
Optional

A SettableMetadata object

The metadata to attach to the file.

Output

A FullMetadata object.

Example

function* setToPng(action) {
  const metadata = yield call(rsf.storage.updateFileMetadata, action.path, {
    contentType: 'image/png'
  });
  return metadata;
}

storage.deleteFile(pathOrRef)
Generator

Deletes a file.

Arguments

TypeDescription
pathOrRef
Optional

String or Firebase Storage Reference

The path or reference of the file in the bucket.

Example

function* deleteFile(action) {
  yield call(rsf.storage.deleteFile, action.path);
}