如何通过drupal8中的fid加载文件?

TAR*_*QAT -3 php drupal-8

这是我的代码

    $fid=$node->get("field_vocabulary")->audio;
    $file =\Drupal\file\Entity\File::load($fid);
    $path = $file->getFileUri();
    $json_arr["audio"]=$path;
Run Code Online (Sandbox Code Playgroud)

但它不起作用!为什么?

显示这个错误

Fatal error: Call to a member function getFileUri() on null in /Applications/MAMP/htdocs/houdun/drupal/modules/article_json/src/Controller/ArticleJsonController.php on line 91
Run Code Online (Sandbox Code Playgroud)

我需要帮助!谢谢!

TAR*_*QAT 5

我修好了它!

    $fid=$node->get("field_vocabulary")->audio;
    $file =File::load($fid);
    $path = file_create_url($file->getFileUri());
    $arr["audio"]=$path;
Run Code Online (Sandbox Code Playgroud)

或者

    $fid=$node->get("field_vocabulary")->audio;
    $file =File::load($fid);
    $path = $file->url();
    $arr["audio"]=$path;
Run Code Online (Sandbox Code Playgroud)