private readonly MediaDefinition
$mediaDefinition,
private readonly EventDispatcherInterface
$eventDispatcher ) { } #[Route(path: '/api/_action/media/{mediaId}/upload', name: 'api.action.media.upload', methods: ['POST'])]
public function upload(Request
$request, string
$mediaId, Context
$context, ResponseFactoryInterface
$responseFactory): Response
{ $tempFile =
tempnam(sys_get_temp_dir(), ''
);
if (!
$tempFile) { throw MediaException::
cannotCreateTempFile();
} $fileName =
$request->query->
getString('fileName',
$mediaId);
$destination =
preg_replace('/[\x00-\x1F\x7F-\xFF]/', '',
$fileName);
if (!\
is_string($destination)) { throw MediaException::
illegalFileName($fileName, 'Filename must be a string'
);
} try { $uploadedFile =
$this->mediaService->
fetchFile($request,
$tempFile);