CloudStorage class abstract

The CloudStorage provides a standardized interface to store binary files in the cloud. The default implementation is to use the database for binary storage, but it can be extended to support Google Cloud, Amazon S3, or any other cloud storage service.

The storage needs to be registered with the Serverpod before starting the server. All methods in this class should throw an CloudStorageException if the method fails.

Implementers

Constructors

CloudStorage(String storageId)
Creates a CloudStorage with the specified storageId. By default, two storages are used by Serverepod public and private. The public should be accessible to everyone (usually through a web interface), while the private is accessed internally only.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
storageId String
Identifies the storage. You can used multiple types cloud storages in a single Serverpod.
getter/setter pair

Methods

createDirectFileUploadDescription({required Session session, required String path, Duration expirationDuration = const Duration(minutes: 10)}) Future<String?>
Creates an URL that a client can post a file to via http post, optionally within the specified duration. After the file has been sent, the verifyDirectFileUpload method should be called. If the file upload hasn't been confirmed before the URL expires, the file will be deleted.
deleteFile({required Session session, required String path}) Future<void>
Deletes the specified file if it exists. Does nothing if the file doesn't exist.
fileExists({required Session session, required String path}) Future<bool>
Returns true if the file exists.
getPublicUrl({required Session session, required String path}) Future<Uri?>
Returns a public link to a file in the storage. If the file isn't public or if no such file exists, null is returned.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
retrieveFile({required Session session, required String path}) Future<ByteData?>
Retrieves a file from the cloud storage or null if no such file exists. If the files are public, the may also be accessible through a web interface.
storeFile({required Session session, required String path, required ByteData byteData, DateTime? expiration, bool verified = true}) Future<void>
Saves a file to the cloud, optionally with an expiration time. The path should be relative to the root directory of the storage (i.e. the string shouldn't start with a slash). This method should throw an IOException if the file upload fails.
toString() String
A string representation of this object.
inherited
verifyDirectFileUpload({required Session session, required String path}) Future<bool>
Call this method once a direct file upload is completed. Failure to call this method will cause the uploaded file to be deleted.

Operators

operator ==(Object other) bool
The equality operator.
inherited