This is a clean Drupal 7.9 Installation with media 1.0-rc2, and a private file system. The system will properly upload an image, but if one imports an image already stored in another directory on the machine, it fails. It makes a copy of the image in the PrivateFiles directory, but does not generate the thumbnail. The system generates the following error in the log: https://example.com/system/files/styles/square_thumbnail/private/IMG_517... access denied (which may be a cause or a symptom).

The actual directory is /usr/local/www/Example.com/PrivateFiles/styles/square_thumbnail/private/ so I am not sure if it has the path incorrect (system/files) or if that is how Drupal shows the path for a private file system.

Comments

majortom’s picture

I did verify that I can directly view the uploaded picture using https://example.com/system/files/Photo%20on%202011-11-13%20at%2016.15.jpg, but get the access denied with https://example.com/system/files/IMG_5544.JPG even logged in as user 1 with node access disabled (From the status report:
"Node Access Permissions Disabled
If the site is experiencing problems with permissions to content, you may have to rebuild the permissions cache. Rebuilding will remove all privileges to content and replace them with permissions based on the current modules and settings. Rebuilding may take some time if there is a lot of content or complex permission settings. After rebuilding has completed, content will automatically use the new permissions.").

dave reid’s picture

Version: 7.x-1.0-rc2 » 7.x-1.x-dev
Assigned: Unassigned » dave reid

Escalating to investigate more this weekend.

Vladimir Pasashnikov’s picture

Hi Dave,

This issue was already risen before, please see 1223670 for example.

I had a look and found that media module registers media in the file_managed table, this part looks OK. However, when module tries to display the media, it calls file_download hook, looking for a modules capable to process URI and it finds file module and image module (in case of image files). Both of these modules do not have a references to that media, so they denied access to the media (media do not registered in field_data_field_imaged table for the image module for example).

I am not sure what is a proper way to fix this, possible file_download hook should be added or some additional references should be created during uploading media files.

Regards,
Vladimir

dave reid’s picture

Yes, I'm leaning towards private files being incompatible with the 'Import' method since doing just a straight import doesn't assign any file 'usage' so hook_file_download() fails.

majortom’s picture

Vladimir -
This may or may not be different than http://drupal.org/node/1223670 in that images uploaded directly using media work fine, it is only those that get imported from another directory on the server that fail. With the import, it does copy the file into the right directory, just not create the thumbnails.

Vladimir Pasashnikov’s picture

Majortom,

To be prescise it may be a different issues. Nevertheless when you upload new media file it:

  • Does upload (copy in your case) new media file in private filesystem.
  • Doesn't create thumbnails as well.
  • Does generate access denied message.
  • Does use the same code to add references to the file and to view it.

So may be you are right and these are different issues, however it looks very similar.

Regards,
Vladimir

majortom’s picture

Vladimir -
When I upload new media into a private filesystem, everything works fine. It stores the file in the correct location, generates a thumbnail and lets me view and use the picture. It is only when trying to import from the local filesystem on the server that things do not work correctly. That is why I clarified that they seem like different issues.

Vladimir Pasashnikov’s picture

Then you are right, it is a different issue. Let Dave has a look and we will see how these two related.

rphillipsfeynman’s picture

Version: 7.x-1.x-dev » 7.x-1.0-rc3

Hello everyone!

I'm new to Drupal and I found myself in the situation described by Vladimir Pasashnikov in post #6. I wonder, have you found any solution to this problem? I would appreciate any suggestion since it is a real site breaking issue for me. Thanks in advance,

Richard

tsvenson’s picture

Version: 7.x-1.0-rc3 » 7.x-1.x-dev

Hi @rphillipsfeynman and thanks for your report. However, please refrain from changing the Version back to an older release. That this issue is set to -dev means the problem you have still persists in the current development code, which is newer than the version you are using, and being worked on.

rphillipsfeynman’s picture

Thanks very much @tsvenson! I'll follow your advice and wait until this issue is solved since it is all I can do with my limited knowledge about Drupal.

hgurol’s picture

The problem described on #6 still exists on version 1.1.
Is there any progress in this issue?

majortom’s picture

Are there any plans to fix this under either 1.x or 2.x versions of media?

ben coleman’s picture

Issue summary: View changes

Any more on this? We just ran into the same thing on version 1.4 - images uploaded to private work fine, but images imported from a directory on the server to private get 'access denied'. Strangely enough, when you go to update a style (admin/config/media/image-styles/edit/

, the modified sample image does not show, and this is also an 'access denied' problem.
majortom’s picture

I was never fixed as far as I can tell. I switched to scald, as it does not suffer from these problems and works quite well.

dave reid’s picture

Assigned: dave reid » Unassigned

I don't believe the mass-import feature will ever be compatible with Drupal 7's private file system. Core requires private files to be 'attached' to some kind of visible entity in order to allow access to those files, and when you do a bulk import, those files live independently, and not related to any kind of field or entity. Naturally Drupal denies access because there is nothing *to* check access on.

koffer’s picture

I found the same problem but only when I try to upload images in the wyswyg editor.

chrisgross’s picture

[deleted]

joseph.olstad’s picture

To make upload folder locations be respected with multi/batch upload , I've patched file_entity with the following patches

#2000934: Allow selection of which folder a file is to on the file/add form
#2198973: Update File Entity + Fix Features Override
#2846795: fatal error argument 3 must be array - when using custom file/add/path with plupload and media_bulk_upload
#2318519: How do I select a file type on /file/add with plupload enabled?

I used these patches to file_entity in combination with some custom form validation code like this:

/*
 * hook form alter for images handled by media_bulk_upload and plupload , multiple bulk upload, so file/add/my-awesome-filepath
 */
function myvalidationmodule_form_file_entity_add_upload_multiple_alter(&$form, &$form_state, $form_id) {

  $current_path = drupal_get_path_alias(current_path());
  $is_imagetype2 = FALSE;
  if (isset($_POST['upload_path'])) {
    if ($_POST['upload_path'] == 'my-awesome-filepath') {
      $is_imagetype2 = TRUE;
    }
  }
  if ($current_path == 'file/add/my-awesome-filepath') {
    $is_imagetype2 = TRUE;
  }

  $form['upload_path']['#disabled'] = FALSE;
  $form['upload_path']['#type'] = 'hidden';//allow user to see path, but not change it

  if ($is_imagetype2) {
    $form_state['storage']['type'] == 'imagetype2';//needs patch to file_entity for this to work... see patches above
  }
  $form['myvalidationmodule_custom_js'] = array(
     '#type' => 'markup',
     '#markup' => '<div><script src="/' . drupal_get_path('module', 'myvalidationmodule') . '/js/mycoolstuff.js' . '"></script></div>',
  );

}
//JAVASCRIPT NOW , save as myvalidationmodule/js/mycoolstuff.js:

(function($) {
    Drupal.behaviors.news_default = {
      attach: function(context, settings) {
        $("input[name=type]:radio").bind( "change", function(event, ui) {
          if ($("input[name=type][value='imagetype2']").is(":checked")) {
            $("input[name=upload_path]").val('my-awesome-filepath');
          } else {
            if ($("input[name=type][value='image']").is(":checked")) {
              $("input[name=upload_path]").val('media');
            }
            if ($("input[name=type][value='document']").is(":checked")) {
              $("input[name=upload_path]").val('documents');
            }
            if ($("input[name=type][value='video']").is(":checked")) {
              $("input[name=upload_path]").val('video');
            }
            if ($("input[name=type][value='audio']").is(":checked")) {
              $("input[name=upload_path]").val('audio');
            }
          }
        });
      }
    }
})(jQuery);

//in my case, imagetype2 is a new image type, and I want all of its files to be uploaded to the imagetype2 folder at the root of the files folder , I also added some image size validation on upload ... so like this:

 function myvalidationmodule_file_validate($file) {
    $image_info = image_get_info($file->uri);
    $image_ratio = ($image_info['width'] / $image_info['height']) * 100;
    $image_ratio = round($image_ratio);
    if ($image_ratio <= 98 || $image_ratio >= 102 ) {
      drupal_set_message('image is not square','error',TRUE);
      $errors[] = 'not square';
      return $errors;
    }
 }
joseph.olstad’s picture

Category: Bug report » Support request
Status: Active » Fixed

see patches for file_entity, in any case, this is not a problem with media

Status: Fixed » Closed (fixed)

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