storage.uploadFile(pathOrRef, file, metadata)
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.
Type | Description | |
---|---|---|
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 | Metadata to attach to the file. |
An UploadTask object.
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)
Use this to upload a raw, base64
, base64url
, or data_url
encoded string to Cloud Storage.
Type | Description | |
---|---|---|
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: |
metadata Optional | Metadata to attach to the file. |
An UploadTask object.
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)
Returns a download url for the file at the specified path.
Type | Description | |
---|---|---|
pathOrRef Optional | String or Firebase Storage Reference | The path or reference of the file in the bucket. |
An URL as a string.
function* downloadFile(action) {
const url = yield call(rsf.storage.getDownloadURL, action.path);
yield call(fetch, url, ...);
}
storage.getFileMetadata(pathOrRef)
Returns the metadata attached to a file.
Type | Description | |
---|---|---|
pathOrRef Optional | String or Firebase Storage Reference | The path or reference of the file in the bucket. |
A FullMetadata object.
function* metadata(action) {
const metadata = yield call(rsf.storage.getFileMetadata, action.path);
return metadata;
}
storage.updateFileMetadata(pathOrRef, newMetadata)
Updates the metadata for a file.
Type | Description | |
---|---|---|
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. |
A FullMetadata object.
function* setToPng(action) {
const metadata = yield call(rsf.storage.updateFileMetadata, action.path, {
contentType: 'image/png'
});
return metadata;
}
storage.deleteFile(pathOrRef)
Deletes a file.
Type | Description | |
---|---|---|
pathOrRef Optional | String or Firebase Storage Reference | The path or reference of the file in the bucket. |
function* deleteFile(action) {
yield call(rsf.storage.deleteFile, action.path);
}