#43511 closed defect (bug) (invalid)
Uploading additional mime type file doesn't show in the media REST endpoint
| Reported by: | dingo_d | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | REST API | Version: | 5.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: | rest-api |
Description
I enabled yaml mime type in my plugin because I need to upload yaml files in the admin.
<?php function enable_mime_types( $mimes ) { $mimes['svg'] = 'image/svg+xml'; $mimes['yaml'] = 'application/x-yaml'; return $mimes; } add_action( 'upload_mimes', 'enable_mime_types' );
This works in the admin, I can upload both svg and yaml files, and I can access them. But when I look at the https://my-page.com/wp-json/wp/v2/media I cannot see yaml files in the list. The svg shows fine, as well as regular png and jpg files.
I searched in the REST handbook, but I saw no filter or action hook where I'd have to enable this mime type in the REST.
Is this a bug or?
Change History (4)
#2
@
8 years ago
- Resolution → invalid
- Status new → closed
You're right, when I test this on the develop version, it shows.
My bad, I'll have to find out what is blocking it.
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi @dingo_bastard, did you test this on a vanilla install?
I just tested this and I can see my
test.yamlfile as the first item in/wp-json/wp/v2/media.I don't see any post mime type filtering for
/wp-json/wp/v2/media, unless we use e.g./wp-json/wp/v2/media?media_type=application.This seems to be the post mime type filtering setup in
WP_REST_Attachments_Controller::prepare_items_query:$media_types = $this->get_media_types(); if ( ! empty( $request['media_type'] ) && isset( $media_types[ $request['media_type'] ] ) ) { $query_args['post_mime_type'] = $media_types[ $request['media_type'] ]; } if ( ! empty( $request['mime_type'] ) ) { $parts = explode( '/', $request['mime_type'] ); if ( isset( $media_types[ $parts[0] ] ) && in_array( $request['mime_type'], $media_types[ $parts[0] ], true ) ) { $query_args['post_mime_type'] = $request['mime_type']; } }