Programmatically update or add a user's avatar I'm trying to update the user avatar in my custom module. Which method shall I use to update the image in db as well as to move the file to public directory?

Thanks.
The file gets stored to file_managed table like this:

// Programmatically create files.
use Drupal\file\Entity\File;
$file = File::create([
  'uid' =&gt; 1,
  'filename' =&gt; $_FILES['file_id']['name'],
  'uri' =&gt; 'public://pictures/' . $_FILES['file_id']['name'],
  'status' =&gt; 1,
]);
$file-&gt;save();


And I manually updated user__user_picture table which is referring to the fid in the above table.

Finally I ended up with move_uploaded_file to store the image to the filesystem. 
I'll proceed with this approach until I find a better way to do the same.

http://www.drupal8.ovh/en/tutoriels/47/create-a-file-drupal-8