Interface MediaOperations

All Known Subinterfaces:
WpRestClient
All Known Implementing Classes:
ApacheWpRestClient, WpBaseRestClient

public interface MediaOperations
Defines operations for managing WordPress media items through the WordPress REST API.

This interface provides methods for creating, retrieving, and listing WpMedia resources.

Operations support standard WordPress REST API features such as pagination, filtering, sorting, and retrieval contexts.

Media operations typically involve handling binary file uploads together with metadata such as MIME type, filename, captions, descriptions, and attachment information.

Implementations are expected to communicate with the /wp-json/wp/v2/media endpoint or compatible APIs.

  • Method Details

    • createMedia

      WpMedia createMedia(@NonNull @NonNull File file, @NonNull @NonNull String fileName, @NonNull @NonNull String mimeType)
      Creates a new media item.

      Uploads a media file to WordPress using the provided file content and metadata.

      The uploaded file is sent to the WordPress media endpoint and results in the creation of a new WpMedia attachment resource.

      Parameters:
      file - the file to upload; must not be null
      fileName - the filename to associate with the uploaded media item; must not be null
      mimeType - the MIME type of the uploaded file, for example image/png; must not be null
      Returns:
      the created WpMedia
    • deleteMedia

      WpMediaDeletionResponse deleteMedia(@NonNull @NonNull Long id)
      Deletes a media item by its unique identifier.
      Parameters:
      id - the ID of the media item to delete; must not be null
      Returns:
      the media item deletion response
    • getMedia

      WpMedia getMedia(@NonNull @NonNull Long id, WpContext context)
      Retrieves a media item by its unique identifier using the given context.

      The context determines which fields are included in the response, for example WpContext.VIEW, WpContext.EDIT, or WpContext.EMBED.

      Parameters:
      id - the ID of the media item to retrieve; must not be null
      context - the retrieval context; may be null, in which case WpContext.VIEW is used
      Returns:
      the matching WpMedia
    • listMedia

      WpPagedResponse<WpMedia> listMedia(@NonNull @NonNull WpPagingQuery pageQuery, WpMediaQuery mediaQuery)
      Retrieves a paginated list of media items using optional filtering and sorting criteria.

      The result set can be refined using WpMediaQuery, for example by filtering on parent, search term, include or exclude lists, or sort order.

      Parameters:
      pageQuery - the pagination settings, including page number and page size; must not be null
      mediaQuery - additional media query parameters; may be null when no extra filtering is needed
      Returns:
      a paginated response containing WpMedia items
    • updateMedia

      WpMedia updateMedia(@NonNull @NonNull Long id, @NonNull @NonNull WpMediaUpdateRequest updateRequest)
      Updates an existing media item.

      Updates a media item in WordPress using the provided request payload.

      Parameters:
      id - the ID of the media item to update; must not be null
      updateRequest - the category update request; must not be null
      Returns:
      the updated WpMedia