Implements hook_field_insert().
function file_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
// Add a new usage of each uploaded file.
foreach ($items as $item) {
file_usage()
->add(file_load($item['fid']), 'file', $entity_type, $entity
->id());
}
}