Я пытаюсь загрузить изображение, чтобы изменить изображение профиля пользователя в Drupal с помощью REST API. И я застрял. Вот мой текущий код:
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"
UserProfileController:
<?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(),
],
]);
}
}
мой запрос почтальона: