Reproduce:

  1. Add a new file type with mime type image/*.
  2. Edit field instance settings to allow only the Image file type and excluding the newly created file type.
  3. Use media internet to add a file that fits the two file types mime rules.
  4. An error occurs "Only the following types of files are allowed to be uploaded: image, etc ..."

Problem:

media_file_validate_types() uses file_get_type() function form file_entity.file_api.inc which will returns the value of the first file type match, regardless if the type is allowed or not for the field.

function file_get_type($file) {
  $types = module_invoke_all('file_type', $file);
  drupal_alter('file_type', $types, $file);

  return empty($types) ? NULL : reset($types);
}

Proposed solution

Replace file_get_type() in media_file_validate_types() by file_entity_get_filetype_candidates() to validate the file against all allowed file types for the field instance.

Related issues

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mkhamash created an issue. See original summary.

mkhamash’s picture

mkhamash’s picture

Status: Active » Needs review
mkhamash’s picture

abu-zakham’s picture

I have re-rolled the patch in #2 to work with the latest development version.

joseph.olstad’s picture

reviewing now

joseph.olstad’s picture

Status: Needs review » Fixed

fixed in 7.x-3.x dev and 7.x-2.x dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.