Skip to content
Snippets Groups Projects
Commit fc499be7 authored by mark burdett's avatar mark burdett
Browse files

Issue #3457133 by mfb, mistergroove: Programatically using file hash to...

Issue #3457133 by mfb, mistergroove: Programatically using file hash to compare an external (temp) file (documentation)
parent 70cba07a
Branches
Tags
No related merge requests found
Pipeline #209077 passed
......@@ -84,6 +84,32 @@ $fids = \Drupal::entityQuery('file')
```
## Duplicate file detection APIs
In addition to being enabled via field widget settings, or on a site-wide basis,
the `FileHashDedupe` validator can also be programmatically added to an upload
form, or executed on a file object:
```php
$validators = ['FileHashDedupe' => []];
$violations = \Drupal::service('file.validator')->validate($file, $validators);
```
The `strict` and `original` boolean options can optionally be added to the
`FileHashDedupe` validator settings array. If `strict` is enabled, temporary
files will also be searched for duplicates, in addition to permanent files. If
`original` is enabled (and the setting to store an additional "original" hash
for each uploaded file is enabled), original file hashes will also be searched
for duplicates, in addition to current file hashes.
The `FileHash::duplicateLookup()` method can also be called directly, given one
of the enabled hash algorithms and a file object, to return a file ID:
```php
$fid = \Drupal::service('filehash')->duplicateLookup('sha256', $file);
```
## Visual output
You can use the included Identicon field formatter to visualize each file hash
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment