files->get('file'); if (!$file) { return $this->json(['error' => 'No file provided.'], Response::HTTP_UNPROCESSABLE_ENTITY); } if ('csv' !== $file->getClientOriginalExtension()) { return $this->json(['error' => 'Only CSV files are accepted.'], Response::HTTP_UNPROCESSABLE_ENTITY); } if ($file->getSize() > 5 * 1024 * 1024) { return $this->json(['error' => 'File too large (max 5 MB).'], Response::HTTP_UNPROCESSABLE_ENTITY); } /** @var User $user */ $user = $this->getUser(); $import = new Import(); $import->setUser($user); $import->setFilePath('pending'); $em->persist($import); $em->flush(); $filePath = sprintf('imports/%d/%d.csv', $user->getId(), $import->getId()); $defaultStorage->write($filePath, file_get_contents($file->getPathname())); $import->setFilePath($filePath); $em->flush(); $bus->dispatch(new ProcessImportMessage($import->getId())); return $this->json([ 'id' => $import->getId(), 'status' => $import->getStatus(), ], Response::HTTP_CREATED); } }