Firebase Storage Library
The Firebase Storage Library provides access to the files in Cloud Storage through the Firebase SDK beyond what FlutterFlow's built-in support provides.
Instructions
To start using this library:
- Import the library into your existing FlutterFlow project.
- Connect your FlutterFlow project to Firebase (if you haven't done so already). The library will default to using the default bucket of your associated Firebase project. You can override this behavior by passing an explicit bucket URL to any of the actions.
- Use the Custom Actions and Custom Functions in your Action Flows.
Custom actions
-
uploadFileToBucket
- Upload a file to any path in any bucket that you have write access to.- Parameters:
- The
bucketName
(String?
) to upload the file to. If you leave this empty, it uses the default bucket of the associated Firebase project. - The
fullPath
(String?
) where the file will be written to inside the bucket. If this is specified, theprefix
parameter is ignored. - The
uploadedFile
(FFUploadedFile
) that is to be uploaded to Cloud Storage. This is the action output of a previousStore media for upload
action. - The
prefix
(folder/directory) (String?
) where the file will be uploaded to. IffullPath
is not specified, the action uses this parameter and thename
of theuploadedFile
to determine the full path where it writes the file.
- The
- Action result:
- If successful, the action result is a
fileObject
containing the full path of the uploaded file.
- If successful, the action result is a
- Parameters:
-
listAllFilesInBucket
- List all files in any bucket that you have read access to.- Parameters:
- The
bucketName
(String?
) to list the files from. If you leave this empty, it uses the default bucket of the associated Firebase project. - The
listType
(StorageListType?
) of the items to list (files, directories, both). If left empty, the action will list both files and prefixes (folders/directories). - The
prefix
(String?
) is the/
separated path from which to list files. If left empty, the action will list the items in the root of the storage bucket.
- The
- Action result:
- If successful, the action results in a
List
offileObject
elements.
- If successful, the action results in a
- Parameters:
-
downloadFile
- Download the data for a file that you have read access to. This downloads the actual data into your application code. If you instead want a public URL to the data, usegetDownloadUrl
instead.- Parameters:
- The
bucketName
(String?
) to download the file from. If you leave this empty, it uses the default bucket of the associated Firebase project. - The
fullPath
(String
) of the file whose data will be read from the bucket.
- The
- Action result:
- If successful, the action result is an
FFUploadedFile
with the data of the file that was read from the bucket.
- If successful, the action result is an
- Parameters:
-
getDownloadUrl
- Get the download URL for a file in a bucket that you have read access to. This URL then provides public, read-only access to the file- Parameters:
- The
bucketName
(String?
) that contains the file. If you leave this empty, it uses the default bucket of the associated Firebase project. - The
fullPath
(String
) of the file for which to get the download URL.
- The
- Action result:
- If successful, the action result is a HTTP URL that allows public access to the file.
- Parameters:
-
getMetadataForFile
- Get the metadata for a file in any bucket that you have read access to- Parameters:
- The
bucketName
(String?
) that contains the file. If you leave this empty, it uses the default bucket of the associated Firebase project. - The
fullPath
(String
) of the file for which to get the download URL.
- The
- Action result:
- If successful, the action result is a
FullMetadata
with all the metadata and custom metadata of the file.
- If successful, the action result is a
- Parameters:
-
updateMetadataForFile
- Update the metadata for a file in any bucket that you have write access to- Parameters:
- The
bucketName
(String?
) that contains the file. If you leave this empty, it uses the default bucket of the associated Firebase project. - The
fullPath
(String
) of the file for which to get the download URL. - The
metadata
(SettableMetadata
) to write to the Cloud Storage bucket for the file. If any value is left out or empty in the metadata, it is left unmodified in Cloud Storage.
- The
- Action result:
- If successful, the action result is a
FullMetadata
with all the metadata and custom metadata of the file after the update.
- If successful, the action result is a
- Parameters:
-
getPathFromUrl
- Get the path for a file based on its (https:// or gs://) URL. This is a synchronous call, as it doesn't require any call to the server.- Parameters
- The
Url
to parse.
- The
- Action result:
- The action result is a
fileObject
derived from the URL.
- The action result is a
- Parameters
-
deleteFileFromBucket
- Deletes a file from any bucket you have write access to.- Parameters:
- The
bucketName
(String?
) that contains the file. If you leave this empty, it uses the default bucket of the associated Firebase project. - The
fullPath
(String
) of the file to delete from the bucket.
- The
- Action result:
- If the action succeeds the file has been deleted. There is no additional information.
- Parameters:
Enums
StorageListType
is an enumeration of the types of items that thelistAllFilesInBucket
action can return. Values:files
: List only the files in the specified path.prefixes
: List only the prefixes in the specified path. You might more commonly refer to these as folders or directories, but since Cloud Storage doesn't actually have support for folders/directories, it uses/
characters in the file names to emulate those and calls them prefixes.filesAndPrefixes
: List both files and prefixes in the specified path.
Data Types
-
fileObject
- the metadata for a file or prefix (folder/directory) in Cloud Storage. It has the following fields:fullPath
(String
) - The full path of the file/prefix inside the storage bucket. The value does not start with a leading/
.isPrefix
(Boolean
) - Indicates whether the object is a file (false
) or prefix (folder/directory) (true
).
-
FullMetadata
- the full metadata of an item in a storage bucket as returned bygetMetadataForFile
, modelled after theFullMetadata
class in the Firebase SDK for Cloud Storage. -
SettableMetadata
- the settable metadata of an item in a storage bucket, as passed to a call toupdateMetadataForFile
, modelled after theSettableMetadata
class in the Firebase SDK for Cloud Storage. -
KeyValuePair
- AString
/String
key/value pair as used for thecustomMetadata
in theFullMetadata
andSettableMetadata
data types.