Skip to content

Commit

Permalink
remove missing filename in file upload WORKAROUND; fix document_type …
Browse files Browse the repository at this point in the history
…parameter name
  • Loading branch information
tobiasgv committed Nov 19, 2024
1 parent 5d0552d commit 4560b14
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
19 changes: 2 additions & 17 deletions src/Rest/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rest/CreateDocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4560b14

Please sign in to comment.