regenerateToken example

$fileData = [
            'id' => Uuid::randomHex(),
            'originalName' => $asciiName . ' öäüß',
            'path' => 'test.csv',
            'expireDate' => new \DateTime(),
        ];
        $filesystem->write($fileData['path']$fileData['originalName']);
        $context = Context::createDefaultContext();
        $fileRepository->create([$fileData]$context);

        $downloadService = new DownloadService($filesystem$fileRepository);
        $accessToken = $downloadService->regenerateToken($context$fileData['id']);

        $response = $downloadService->createFileResponse($context$fileData['id']$accessToken);
        static::assertIsString($header = $response->headers->get('Content-Disposition'));
        static::assertStringContainsString($asciiName$header);

        $response->sendContent();
        $this->expectOutputString($fileData['originalName']);
    }

    public function testSlashFilename(): void
    {
        
$message = new ImportExportMessage($context$logEntity->getId()$logEntity->getActivity());

        $this->messageBus->dispatch($message);

        return new Response('', Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/import-export/file/prepare-download/{fileId}', name: 'api.action.import_export.file.prepare-download', methods: ['POST'])]     public function prepareDownload(string $fileId, Context $context): Response
    {
        $token = $this->downloadService->regenerateToken($context$fileId);

        return new JsonResponse(['accessToken' => $token]);
    }

    #[Route(path: '/api/_action/import-export/file/download', name: 'api.action.import_export.file.download', defaults: ['auth_required' => false], methods: ['GET'])]     public function download(Request $request, Context $context): Response
    {
        /** @var array<string> $params */
        $params = $request->query->all();
        $definition = new DataValidationDefinition();
        $definition->add('fileId', new NotBlank()new Type('string'));
        
Home | Imprint | This part of the site doesn't use cookies.