When using the Media file selector widget with an Image field, the minimum image resolution settings for that field are ignored, allowing a user to upload a smaller image and save the node successfully. The Media file selector widget should work like the core Image widget, which prevents the user from saving the node and displays an explanatory error (e.g. "The specified file image.jpg could not be uploaded. The image is too small; the minimum dimensions are 738x395 pixels.")

Comments

wmostrey’s picture

dave reid’s picture

Title: Media file selector widget ignores minimum image resolution for Image field » Media file selector widget ignores minimum image resolution and maximum filesize for Image field

I think this is closely enough related to #1226992: Media file selector widget ignores maximum filesize that we don't need two issues for it.

effulgentsia’s picture

If #1223252: Media widget on filefield ignores "Allowed file extensions" filefield setting is a stable release blocker, then I think this should be too, so tagging.

dave reid’s picture

Yep, agreed. I missed adding the tag here.

dave reid’s picture

Version: 7.x-1.0-beta5 » 7.x-1.x-dev
dave reid’s picture

Title: Media file selector widget ignores minimum image resolution and maximum filesize for Image field » Widget does not respect settings in file_field_instance_settings_form (directory, extensions, file size, description field)
Version: 7.x-1.x-dev » 7.x-2.x-dev
idflood’s picture

Not sure if it's the correct way of doing this, but here is a copy/paste of 2 posts I made on a duplicate (#1140434: Size limits and other settings like in FileField).

possibly related or even duplicates:

Here are some initial observations:

  • The standard image field setup the size validation in image_field_widget_form (modules/image/image.field.inc, line 304)
  • The equivalent media function is media_field_widget_form (media/includes/media.fields.inc line 217)
  • There is a little @todo in the media_field_widget_form that make me think there will be some more work needed (to pass field settings to the popup, but not sure about this)
  • Needs to handle 2 different validations. Images uploaded and images selected from the library.
  • The popup is created in media.browser.inc (media_media_browser_plugin_view line 209). It seems $params doesn't contains the field instance settings like minimum image size.
  • The forms are created in media.pages.inc (media_add_upload line 171 and media_add_upload_multiple line 259(

So, for uploaded files I could imagine something as simple as:

if ($settings['max_resolution'] || $settings['min_resolution']) {
  $validators['file_validate_image_resolution'] = array($settings['max_resolution'], $settings['min_resolution']);
}

But how would it be possible to access this $settings from media_add_upload() ? If I understand correctly we need to first pass these settings to media_media_browser_plugin_view() and then to the forms. Is that right? Any other solution?

dave reid’s picture

Title: Widget does not respect settings in file_field_instance_settings_form (directory, extensions, file size, description field) » Widget does not respect settings in image_field_instance_settings_form (min/max resolution, alt, title)

I mistitled this issue. Apologies.

idflood’s picture

Status: Active » Needs review
StatusFileSize
new2.07 KB

I've looked a little more in media code and found the media_get_browser_params() method. With this method it becomes easy to get the field instance settings in media_add_upload.

So here is a first patch which make media use the field instance settings when possible. It's already working relatively well on my tests but the patch isn't complete. I've applied the field instance settings after the media settings. So whenever you define a field instance setting it will override the similar media settings. This should be ok with min/max_resolution but what about file_extension?

wmostrey’s picture

Version: 7.x-2.x-dev » 7.x-2.0-unstable1

The patch in #9 also applies cleanly to 7.x-1.0-beta5 and it works as advertised. I tested it with min/max resolution and file extension.

idflood’s picture

Version: 7.x-2.0-unstable1 » 7.x-2.x-dev
StatusFileSize
new2.9 KB

I've found an issue where the generic file widget setting for file extension was always used. So I changed this specific setting to be used only if there is no media "type" enabled (audio/image/video/other).

There is also an added condition on "description_field" setting but I don't know what to do with it yet. I've also tried to implement the "file_directory" setting but finally commented the first try (in media_add_upload_submit()).

michaelfavia’s picture

Applied patch in #11 to no effect. I just want to make sure i am reading this issue correctly: Image fields that use the media widget for their selector SHOULD respect the max/min/alt/title settings on the content type settings.

It is successfully going into the upload step and transcribing the "$field_settings" to "$validators".

As i step through it in the debugger though it seems to never go through the imagefield validation checks only the file.inc ones.

idflood’s picture

StatusFileSize
new2.89 KB

The patch isn't complete now and will not work for alt/title. There is 4 things implemented in it: max_resolution, min_resolution, file_extensions and max_filesize.

It should work for "file" or "image" fields with the "media selector" widget. In the field settings you can specifiy the settings discussed above. There is a special case for "file_extensions". This settings override the media "type" setting only if no media are checked (video/image/audio/other).

Here is a reroll of the last patch only fixing 3 trailing spaces.

dave reid’s picture

Assigned: Unassigned » arthurf
dave reid’s picture

Title: Widget does not respect settings in image_field_instance_settings_form (min/max resolution, alt, title) » Widget does not respect settings in image_field_instance_settings_form (min/max resolution)
Assigned: arthurf » Unassigned

Shrinking scope.

dave reid’s picture

Assigned: Unassigned » dave reid
dave reid’s picture

Status: Needs review » Needs work

The last submitted patch, 1223794-validate-image-min-max-resolution.patch, failed testing.

dave reid’s picture

dave reid’s picture

Status: Needs work » Needs review
dave reid’s picture

Wappie08’s picture

Maybe a dumb question but where exactly can I set the max file size for my media (gallery) images ??


Greetings Wappie

Status: Fixed » Closed (fixed)

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

Rob_Feature’s picture

Status: Closed (fixed) » Active

Reopening this to get some clarity (I realize it's old...sorry):

If I leave the setting blank for filesize (in the filefield), it SHOULD default to the maximum, correct? I'm not seeing this behavior.

If I leave the max size blank, it says `1000 bytes' as opposed to my php max (which is listed as 128MB).

If I put in 128MB manually, it works, but if I leave it empty, it does not.

Anyone else?

dave reid’s picture

@Rob_Feature: The logic for the max upload size is the following:

  // Validate file size but do not allow anything higher than file_upload_max_size().
  $max_filesize = file_upload_max_size();
  if (!empty($params['max_filesize']) && $params['max_filesize'] < $max_filesize) {
    $validators['file_validate_size'] = array(parse_size($params['max_filesize']));
  }
  elseif (($tmp = media_variable_get('max_filesize')) && $tmp < $max_filesize) {
    $validators['file_validate_size'] = array(parse_size($tmp));
  }
  else {
    $validators['file_validate_size'] = array($max_filesize);
  }

I'd check what your media variable is set to.

dave reid’s picture

Status: Active » Closed (fixed)

If this needs to be adjusted, please file a new bug report.

patrick.thurmond@gmail.com’s picture

Issue summary: View changes
Issue tags: -

Was this ever supposed to be applied to the 1.x branch? I am using 1.4 and seeing this problem there and the 1.5 notes say nothing of this issue nor anything similar.

dave reid’s picture

@pthurmond This was committed before the 7.x-1.0 release was even made, so it should be fixed. If you are encountering a bug, please file a new issue instead of commenting on an issue that has been marked as closed for three years.

erwangel’s picture

Category: Bug report » Feature request
Related issues: +#1140434: Size limits and other settings like in FileField

I'm sorry to reopen this but although it resolves the subject's issue about image_field min/max resolution, it doesn't implement these settings for the media/file_field as requested by (#1140434: Size limits and other settings like in FileField https://www.drupal.org/project/media/issues/1140434) which was marked as duplicated. So I changed category issue to "feature request". Could we have min/max resolution and the appropriate file_validate_image_resolution for media files also ? This can be useful in many situations especially when allowing users to upload large files pictures as is the case in nowadays with high resolution cameras (even with phone devices) but we don't need to keep all these huge original files for just a web/screen display. Not very friendly to ask users to resize their images before uploading. Of course image styles allow a resize for each display case but this doesn't avoid storage of the useless original mbytes. So we need to resize these photos in a reasonable resolution for a quality display but not store them in their original size.

joseph.olstad’s picture

erwangel
I'm pretty sure you can resolve this by one of these contrib modules for cropping/resizing. If you find one that serves your use case please let us know.

see the link https://www.drupal.org/node/1179172