Can't get fid of the saved file after file_save_data
In Drupal 7, $file_object-&gt;fid should work.

Looking at the code you have tried ($file_object-&gt;fid-&gt;value, file_object-&gt;id()), I guess you have been mixing up Drupal 8 and Drupal 7 documentation.