Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#43511 closed defect (bug) (invalid)

Uploading additional mime type file doesn't show in the media REST endpoint

Reported by: dingo_d's profile dingo_d Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.1
Component: REST API Keywords:
Focuses: rest-api Cc:

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)

#1 @birgire
7 years ago

Hi @dingo_bastard, did you test this on a vanilla install?

I just tested this and I can see my test.yaml file 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'];
    }
}

Last edited 7 years ago by birgire (previous) (diff)

#2 @dingo_bastard
7 years ago

  • Resolution set to invalid
  • Status changed from new to 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.

#3 @birgire
7 years ago

  • Milestone Awaiting Review deleted

I hope you sort this out, probably a hook callback in your plugin/theme modifying the media rest query.

#4 @dd32
6 years ago

  • Reporter changed from dingo_bastard to dingo_d
Note: See TracTickets for help on using tickets.