title: Drupal 8 Update User Profile Picture Through REST API
body: <p>I'm trying to upload image to change a user profile picture in Drupal with REST API. And I got stuck. Here is my current code:</p>
  
  <p>my_module.routing.yml:</p>
  
  <pre><code>my_module.api.user.profile.update_picture:
    path: '/api/user/profile/update-picture'
    defaults:
      _controller: \Drupal\my_module\Controller\UserProfileController::updatePicture
    requirements:
      _access: "TRUE"
  </code></pre>
  
  <p>UserProfileController:</p>
  
  <pre><code>&lt;?php
  
  namespace Drupal\my_module\Controller;
  
  use Drupal\Core\Controller\ControllerBase;
  use Symfony\Component\HttpFoundation\JsonResponse;
  use Symfony\Component\HttpFoundation\Request;
  
  class UserProfileController extends ControllerBase
  {
    protected $currentUser;
  
    public function __construct()
    {
      $this-&gt;currentUser = \Drupal::currentUser();
    }
  
    public function updatePicture(Request $request)
    {
  
      $file = file_save_upload('image');
      var_dump($file); die; // &lt;----- returned false in my postman below
  
      $user = \Drupal\user\Entity\User::load($this-&gt;currentUser-&gt;id());
      $user-&gt;set('user_picture', $file-&gt;id());
      $user-&gt;save();
  
      return new JsonResponse([
          'success' =&gt; FALSE,
          'debug' =&gt; [
              'userId' =&gt;  $this-&gt;currentUser-&gt;id(),
          ],
      ]);
    }
  }
  </code></pre>
  
  <p>my postman request:
  <a href="https://i.stack.imgur.com/jxZrY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jxZrY.png" alt="enter image description here"></a></p>