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.
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!!
Comment | File | Size | Author |
---|---|---|---|
#16 | plupload_1814744_7.x-1.1_16.patch | 1.58 KB | tobiasb |
#6 | plupload_tmp_uri_validate_1814744_6.patch | 1.75 KB | slashrsm |
#4 | plupload_add_tmp_uri_validate_1814744_4.patch | 682 bytes | slashrsm |
#1 | plupload_hook_validate_uri.patch | 561 bytes | Kevin Hankens |
Comments
Comment #1
Kevin Hankens CreditAttribution: Kevin Hankens commentedComment #2
slashrsm CreditAttribution: slashrsm commentedThis 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()?
Comment #3
Kevin Hankens CreditAttribution: Kevin Hankens commentedUnfortunately, 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!
Comment #4
slashrsm CreditAttribution: slashrsm commentedWhat about this? Gives you the info you need, but keeps current behaviour untouched.
Comment #5
Kevin Hankens CreditAttribution: Kevin Hankens commentedHey. 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.
Comment #6
slashrsm CreditAttribution: slashrsm commentedI 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
Comment #7
Kevin Hankens CreditAttribution: Kevin Hankens commentedNice, this patch definitely works for my needs. I'll keep an eye on this thread to see what others think.
Thx!
Comment #8
slashrsm CreditAttribution: slashrsm commentedRelated blog post: http://janezurevc.name/drupals-plupload-integration-filevalidate
Hope to get some more feedback.
Comment #9
Anonymous (not verified) CreditAttribution: Anonymous commentedI 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.
Comment #10
slashrsm CreditAttribution: slashrsm commentedI 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?
Comment #11
Kevin Hankens CreditAttribution: Kevin Hankens commentedYeah, 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!
Comment #12
slashrsm CreditAttribution: slashrsm commentedCommited to 7.x-2.x. Thanks!
Comment #13
slashrsm CreditAttribution: slashrsm commentedComment #15
tobiasbThis 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.
Comment #16
tobiasbThe 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.
Comment #17
slashrsm CreditAttribution: slashrsm commentedThat's strange.... I rolled 7.x-1.2 which includes some oher nice bugfixes anyway.