I'm trying to validate a plupload-uploaded file using hook_file_validate(), but the $file object from plupload_element_validate() contains dummy values. I need to get access to the temporary URI so that I can actually look at the file (as opposed to just checking extensions) that was uploaded. I'm not sure if this patch is too much of a hack, but using the temporary URI as the $file->uri seems to work the way I need it to.

Thanks!!

Comments

Kevin Hankens’s picture

Status:Active» Needs review
StatusFileSize
new561 bytes
slashrsm’s picture

Status:Needs review» Postponed (maintainer needs more info)

This changes current behaviour, which is not OK.

Are you not able to access $element['#value'] in your validate callback. Just like module does in plupload_element_validate()?

Kevin Hankens’s picture

Unfortunately, in hook_file_validate(), I just get what plupload sends. In this case $file->uri is invalid. In my use case, I need to scan all files generically with hook_file_validate and cannot add validation callbacks to specific forms.

Thanks!

slashrsm’s picture

Status:Postponed (maintainer needs more info)» Needs review
StatusFileSize
new682 bytes

What about this? Gives you the info you need, but keeps current behaviour untouched.

Kevin Hankens’s picture

Hey. Thanks for the suggestion! Ideally, I would like my implementation of hook_file_validate() to be consistent and not have to write cases for every drupal module that uses the file api in a slightly different way. You know? This is for the antivirus module, so it needs to just generically look at $file->uri and make a decision.

slashrsm’s picture

Category:bug» task
StatusFileSize
new1.75 KB

I understand your concerns. It is also more logical to send around uri, that is actually valid (meaning that something can be found under it).

I slightly changed this solution to be a bit cleaner and more logical. I propose to create file object using temp path, but to change filename and filemime after that. This will allow file_validate_extension() to keep working as expected.

What do you think? This breaks API a bit, so I'll be very conservative committing this. Will definitely wait for more reviews than usual before doing that.

This issue is somehov related #685818: Provide an API function to convert a URI to a file object

Kevin Hankens’s picture

Nice, this patch definitely works for my needs. I'll keep an eye on this thread to see what others think.

Thx!

slashrsm’s picture

Related blog post: http://janezurevc.name/drupals-plupload-integration-filevalidate

Hope to get some more feedback.

morningtime’s picture

I think this patch is necessary. This is one of the reasons why I abandoned plupload in the past, and the patch seems necessary to make it work correctly.

slashrsm’s picture

I decided to create 7.x-2.x branch and to commit this to it. I think this is the only right way to go. What do you think?

Kevin Hankens’s picture

Yeah, since it changes the API, a new branch seems totally appropriate. Anyone who needs the feature more urgently for 1.x can apply the patch from #6.

Thanks!

slashrsm’s picture

Version:7.x-1.0» 7.x-2.x-dev

Commited to 7.x-2.x. Thanks!

slashrsm’s picture

Status:Needs review» Fixed

Status:Fixed» Closed (fixed)

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

tobiasb’s picture

Version:7.x-2.x-dev» 7.x-1.x-dev
Assigned:Unassigned» tobiasb
Category:task» bug
Status:Closed (fixed)» Needs work

This also needs a fix in 1.x. This is not really a API change, because plupload_element_validate() is buggy, The filehash module can not do his work or all modules which implements hook_file_validate().

In combination with file_entity, there is no other way todo this, because this module calls file_validate().
Therefore lets fix this and do it on the right way. I will provide a patch later.

tobiasb’s picture

Assigned:tobiasb» Unassigned
Status:Needs work» Closed (fixed)
StatusFileSize
new1.58 KB

The bug is already fixed in 7.x-1.x. But somehow the fix is not in 7.x-1.1, but the commit http://drupalcode.org/project/plupload.git/commit/141e997e41b12c7de07d5f... in 1.x branch http://drupalcode.org/project/plupload.git/shortlog/refs/heads/7.x-1.x was before that. Really strange.

The attached patch is for the current stable release 7.x-1.1. Useful for drush make or something.

slashrsm’s picture

That's strange.... I rolled 7.x-1.2 which includes some oher nice bugfixes anyway.

  • Commit 141e997 on 7.x-1.x, 7.x-2.x, 8.x-1.x by slashrsm:
    Issue #1814744 by slashrsm, Kevin Hankens: File URI not available to...