0

Currently, I'm facing an issue while uploading a file.

I'm fetching the file tid with hook_entity_presave:

$file_tid = $entity->get('field_photos_photos')
  ->getValue()[0]['target_id'];

if(!empty($file_tid)) {

  $uploaded_file_uri= \Drupal::entityTypeManager()
    ->getStorage('file')
    ->load($file_tid)
    ->getFileUri();

}

However, I cannot get the file tid.

  • 2
    There are easier ways, e.g. $uploaded_file_uri = $entity->field_photos_photos->entity->getFileUri(); – Clive May 30 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.