Interface MediaOperations
- All Known Subinterfaces:
WpRestClient
- All Known Implementing Classes:
ApacheWpRestClient,WpBaseRestClient
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 Summary
Modifier and TypeMethodDescriptioncreateMedia(@NonNull File file, @NonNull String fileName, @NonNull String mimeType) Creates a new media item.deleteMedia(@NonNull Long id) Deletes a media item by its unique identifier.Retrieves a media item by its unique identifier using the given context.listMedia(@NonNull WpPagingQuery pageQuery, WpMediaQuery mediaQuery) Retrieves a paginated list of media items using optional filtering and sorting criteria.updateMedia(@NonNull Long id, @NonNull WpMediaUpdateRequest updateRequest) Updates an existing media item.
-
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
WpMediaattachment resource.- Parameters:
file- the file to upload; must not benullfileName- the filename to associate with the uploaded media item; must not benullmimeType- the MIME type of the uploaded file, for exampleimage/png; must not benull- Returns:
- the created
WpMedia
-
deleteMedia
Deletes a media item by its unique identifier.- Parameters:
id- the ID of the media item to delete; must not benull- Returns:
- the media item deletion response
-
getMedia
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, orWpContext.EMBED.- Parameters:
id- the ID of the media item to retrieve; must not benullcontext- the retrieval context; may benull, in which caseWpContext.VIEWis 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 benullmediaQuery- additional media query parameters; may benullwhen no extra filtering is needed- Returns:
- a paginated response containing
WpMediaitems
-
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 benullupdateRequest- the category update request; must not benull- Returns:
- the updated
WpMedia
-