diff --git a/src/Rest/Common.php b/src/Rest/Common.php index 9ca18ca..041b570 100644 --- a/src/Rest/Common.php +++ b/src/Rest/Common.php @@ -5,7 +5,6 @@ namespace Dbp\Relay\BlobConnectorCampusonlineDmsBundle\Rest; use Dbp\Relay\BlobConnectorCampusonlineDmsBundle\Entity\Error; -use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\Request; @@ -19,29 +18,15 @@ class Common public static function getAndValidateUploadedFile(Request $request, string $fileParameterName): File { $uploadedFile = $request->files->get($fileParameterName); - if ($uploadedFile === null) { - // look into form parameters if the file was sent in the form of a binary string parameter, - // i.e. without the 'filename' directive in the 'content-disposition' header, which CO currently does. - $binaryContent = $request->request->get($fileParameterName); - if ($binaryContent === null) { - throw new Error(Response::HTTP_BAD_REQUEST, 'parameter \'binary_content\' must not be empty', - errorCode: 'REQUIRED_PARAMETER_MISSING', errorDetail: 'binary_content'); - } - $filesystem = new Filesystem(); - $tempFilePath = $filesystem->tempnam('/tmp', 'php'); - file_put_contents($tempFilePath, $binaryContent); - $uploadedFile = new File($tempFilePath); - } - if ($uploadedFile === null) { throw new Error(Response::HTTP_BAD_REQUEST, 'Parameter \''.$fileParameterName.'\' is required', errorCode: 'REQUIRED_PARAMETER_MISSING', errorDetail: $fileParameterName); } - if ($uploadedFile instanceof File === false) { + if ($uploadedFile instanceof UploadedFile === false) { throw new Error(Response::HTTP_BAD_REQUEST, 'Parameter \''.$fileParameterName.'\' must be a file stream', errorCode: 'PARAMETER_TYPE_INVALID', errorDetail: $fileParameterName); } - if ($uploadedFile instanceof UploadedFile && $uploadedFile->getError() !== UPLOAD_ERR_OK) { + if ($uploadedFile->getError() !== UPLOAD_ERR_OK) { throw new Error(Response::HTTP_BAD_REQUEST, sprintf('file stream upload failed: %d', $uploadedFile->getError()), errorCode: 'FILE_UPLOAD_FAILED', errorDetail: $fileParameterName); } diff --git a/src/Rest/CreateDocumentController.php b/src/Rest/CreateDocumentController.php index 9d885e9..84ca01b 100644 --- a/src/Rest/CreateDocumentController.php +++ b/src/Rest/CreateDocumentController.php @@ -52,7 +52,7 @@ public function __invoke(Request $request): Document throw new Error(Response::HTTP_BAD_REQUEST, 'The metadata of the document is not valid JSON', errorCode: 'RESOURCE_MALFORMED_MDATA', errorDetail: 'metadata'); } - $documentType = $request->request->get('documentType'); + $documentType = $request->request->get('document_type'); $document = new Document(); $document->setMetaData($metadataArray);