Php Drupal8通过RESTAPI更新用户配置文件图片

Php Drupal8通过RESTAPI更新用户配置文件图片,php,drupal,drupal-8,drupal-modules,Php,Drupal,Drupal 8,Drupal Modules,我正试图上传图片,用RESTAPI在Drupal中更改用户配置文件图片。我被卡住了。这是我目前的代码: my_module.routing.yml: my_module.api.user.profile.update_picture: path: '/api/user/profile/update-picture' defaults: _controller: \Drupal\my_module\Controller\UserProfileController::updatePi

我正试图上传图片,用RESTAPI在Drupal中更改用户配置文件图片。我被卡住了。这是我目前的代码:

my_module.routing.yml:

my_module.api.user.profile.update_picture:
  path: '/api/user/profile/update-picture'
  defaults:
    _controller: \Drupal\my_module\Controller\UserProfileController::updatePicture
  requirements:
    _access: "TRUE"
用户配置文件控制器:

<?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->currentUser = \Drupal::currentUser();
  }

  public function updatePicture(Request $request)
  {

    $file = file_save_upload('image');
    var_dump($file); die; // <----- returned false in my postman below

    $user = \Drupal\user\Entity\User::load($this->currentUser->id());
    $user->set('user_picture', $file->id());
    $user->save();

    return new JsonResponse([
        'success' => FALSE,
        'debug' => [
            'userId' =>  $this->currentUser->id(),
        ],
    ]);
  }
}