Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Reproduce:
- Add a new file type with mime type image/*.
- Edit field instance settings to allow only the Image file type and excluding the newly created file type.
- Use media internet to add a file that fits the two file types mime rules.
- 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
-
Using file_entity_get_filetype_candidates() will trigger an error in file_entity_access() "Undefined property: stdClass::$fid" since the file is not uploaded yet and does not have a fid.
Reference issue #2312603: Undefined property: stdClass::$fid in file_entity_access() .
Comment | File | Size | Author |
---|---|---|---|
#5 | media_internet_fails_to-2610058-5.patch | 632 bytes | abu-zakham |
| |||
#2 | media_internet_fails_to-2610058-2.patch | 632 bytes | mkhamash |
Comments
Comment #2
mkhamash CreditAttribution: mkhamash as a volunteer and at Vardot commentedComment #3
mkhamash CreditAttribution: mkhamash as a volunteer and at Vardot commentedComment #4
mkhamash CreditAttribution: mkhamash as a volunteer and at Vardot commentedComment #5
abu-zakham CreditAttribution: abu-zakham at Vardot commentedI have re-rolled the patch in #2 to work with the latest development version.
Comment #6
joseph.olstadreviewing now
Comment #9
joseph.olstadfixed in 7.x-3.x dev and 7.x-2.x dev