Skip to content

Delete Local Media

Endpoints

DeleteLocalMedia

This API deletes the local media from the disk of your own server. This includes any local thumbnails and copies of media downloaded from remote homeservers. This API will not affect media that has been uploaded to external media repositories (e.g https://github.com/turt2live/matrix-media-repo/).

Source code in matrix_admin_sdk/endpoints/v1/delete_local_media.py
class DeleteLocalMedia(Endpoint):
    """
    This API deletes the local media from the disk of your own server.
    This includes any local thumbnails and copies of media downloaded from remote
    homeservers. This API will not affect media that has been uploaded
    to external media repositories
    (e.g https://github.com/turt2live/matrix-media-repo/).
    """

    async def specific_local_media(
        self, server_name: str, media_id: str
    ) -> DeleteLocalMediaModel:
        """
        Delete a specific media_id
        Args:
            server_name: The name of your local server (e.g matrix.org)
            media_id:The ID of the media (e.g abcdefghijklmnopqrstuvwx)

        Returns: DeleteLocalMediaModel

        """
        url = self.url(f"media/{server_name}/{media_id}")
        result = await self.request(RequestMethods.DELETE, url)
        res: DeleteLocalMediaModel = DeleteLocalMediaModel.from_dict(result)
        return res

    async def local_media_by_date_or_size(
        self,
        server_name: str,
        before_ts: int,
        size_gt: int = 0,
        keep_profiles: bool = True,
    ):
        """
        Delete local media by date or size
        Args:
            server_name: The name of your local server (e.g matrix.org).
            before_ts: Unix timestamp in milliseconds. Files that were last used before
                this timestamp will be deleted. It is the timestamp of last access,
                not the timestamp when the file was created.
            size_gt: Size of the media in bytes. Files that are larger will be deleted.
                Defaults to 0.
            keep_profiles: Switch to also delete files that are still used in image
                data (e.g user profile, room avatar). If false these files will be
                deleted. Defaults to true.

        Returns:

        """
        keep_profile_string = "true" if keep_profiles else "false"

        url = self.url(
            f"media/{server_name}/delete?before_ts={before_ts}&size_gt={size_gt}&keep_profiles={keep_profile_string}"
        )

        result = await self.request(RequestMethods.POST, url, json={})
        return DeleteLocalMediaModel.from_dict(result)

local_media_by_date_or_size(self, server_name, before_ts, size_gt=0, keep_profiles=True) async

Delete local media by date or size

Parameters:

Name Type Description Default
server_name str

The name of your local server (e.g matrix.org).

required
before_ts int

Unix timestamp in milliseconds. Files that were last used before this timestamp will be deleted. It is the timestamp of last access, not the timestamp when the file was created.

required
size_gt int

Size of the media in bytes. Files that are larger will be deleted. Defaults to 0.

0
keep_profiles bool

Switch to also delete files that are still used in image data (e.g user profile, room avatar). If false these files will be deleted. Defaults to true.

True
Source code in matrix_admin_sdk/endpoints/v1/delete_local_media.py
async def local_media_by_date_or_size(
    self,
    server_name: str,
    before_ts: int,
    size_gt: int = 0,
    keep_profiles: bool = True,
):
    """
    Delete local media by date or size
    Args:
        server_name: The name of your local server (e.g matrix.org).
        before_ts: Unix timestamp in milliseconds. Files that were last used before
            this timestamp will be deleted. It is the timestamp of last access,
            not the timestamp when the file was created.
        size_gt: Size of the media in bytes. Files that are larger will be deleted.
            Defaults to 0.
        keep_profiles: Switch to also delete files that are still used in image
            data (e.g user profile, room avatar). If false these files will be
            deleted. Defaults to true.

    Returns:

    """
    keep_profile_string = "true" if keep_profiles else "false"

    url = self.url(
        f"media/{server_name}/delete?before_ts={before_ts}&size_gt={size_gt}&keep_profiles={keep_profile_string}"
    )

    result = await self.request(RequestMethods.POST, url, json={})
    return DeleteLocalMediaModel.from_dict(result)

specific_local_media(self, server_name, media_id) async

Delete a specific media_id

Parameters:

Name Type Description Default
server_name str

The name of your local server (e.g matrix.org)

required
media_id str

The ID of the media (e.g abcdefghijklmnopqrstuvwx)

required
Source code in matrix_admin_sdk/endpoints/v1/delete_local_media.py
async def specific_local_media(
    self, server_name: str, media_id: str
) -> DeleteLocalMediaModel:
    """
    Delete a specific media_id
    Args:
        server_name: The name of your local server (e.g matrix.org)
        media_id:The ID of the media (e.g abcdefghijklmnopqrstuvwx)

    Returns: DeleteLocalMediaModel

    """
    url = self.url(f"media/{server_name}/{media_id}")
    result = await self.request(RequestMethods.DELETE, url)
    res: DeleteLocalMediaModel = DeleteLocalMediaModel.from_dict(result)
    return res

Models

DeleteLocalMediaModel

DeleteLocalMedia class

Attributes:

Name Type Description
deleted_media list[str]

List of deleted media_id

total int

Total number of deleted media_id

Source code in matrix_admin_sdk/models/v1/delete_local_media.py
class DeleteLocalMediaModel(BaseModel):
    """
    DeleteLocalMedia class
    Attributes:
        deleted_media (list[str]): List of deleted media_id
        total (int): Total number of deleted media_id
    """

    deleted_media: List[str]
    total: int