MediaRepository class Null safety

Media manager class that can work with local and remote media files. Remote media files are stored to the CMS via GraphQL upload. Local files receive random IDs and are not persisted across application restarts.

This class supports both assets stored in Strapi's media library as well as videos that are uploaded and transcoded via Mux. Mux assets are only supported read-only. If an attempt to upload a video is made, the video ends up in Strapi's media library without transcoding via Mux.

Constructors

MediaRepository(GraphQLClient graphQLClient, Logger? logger)

Properties

graphQLClient GraphQLClient
final
hashCode int
The hash code for this object.
read-onlyinherited
logger Logger?
final
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

addLocalAsset(String url) MediaAsset
Adds a local asset to the repository. Local means that the asset only exists as a local entity. Format variants will not be generated. For now, there's no format detection so mimetypes will not be created. With this call, ownership is transferred to the repository. This in turn means that local assets will be deleted from the file system when delete() is called. path must be a local URI that can be passed to File() Local assets DO NOT PERSIST, their content is lost after app restart. They are only meant for transient use and should be converted to remote assets as soon as possible.
addRemoteAsset(String url, MediaType mediaType) Future<MediaAsset?>
Adds a remote asset to the repository. This will upload the asset to the CMS, where it will be stored and resized. Returns a MediaAsset with a persistent ID that can be used for future reference to the asset. Returns null in case of failure. The asset to be stored is referenced by a local device URL. The repository does not assume ownership of the file, the caller needs to clean up if the file is temporary.
delete(MediaAsset asset) Future<void>
Deletes the asset. The asset cannot be used anymore afterwards. For local assets the file will be deleted, for remote assets the asset will be deleted from the CMS.
getAssetById(String id) Future<MediaAsset?>
Returns a MediaAsset instance for a CMS asset that is referenced by ID. Returns null if the asset could not be retrieved from the CMS. Do not call for assets that are stored locally as it will always return null.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
uploadLocalAsset(MediaAsset localAsset, MediaType mediaType) Future<MediaAsset?>
Uploads a local asset to remote storage. If successful, deletes the local asset. This means that the new asset returned must be used after this function has been called. Returns null in case of failure.

Operators

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