diff --git a/src/Controller/FileUpload.php b/src/Controller/FileUpload.php index 6c69ca0..5e87ef8 100644 --- a/src/Controller/FileUpload.php +++ b/src/Controller/FileUpload.php @@ -111,6 +111,9 @@ class FileUpload { * Thrown when there are validation errors. * @throws \Drupal\Core\Entity\EntityStorageException * Thrown if the upload's target resource could not be saved. + * @throws \Exception + * Thrown if an exception occurs during a subrequest to fetch the newly + * created file entity. */ public function handleFileUploadForExistingResource(Request $request, ResourceType $resource_type, $file_field_name, FieldableEntityInterface $entity) { $field_definition = $this->validateAndLoadFieldDefinition($resource_type->getEntityTypeId(), $resource_type->getBundle(), $file_field_name); diff --git a/src/ForwardCompatibility/FileUploader.php b/src/ForwardCompatibility/FileUploader.php index 80e623d..3734daf 100644 --- a/src/ForwardCompatibility/FileUploader.php +++ b/src/ForwardCompatibility/FileUploader.php @@ -196,12 +196,10 @@ class FileUploader implements FileUploaderInterface { */ public static function validateAndParseContentDispositionHeader(Request $request) { // First, check the header exists. - if (!$request->headers->has('content-disposition')) { + if (!$request->headers->has('content-disposition') || !($content_disposition = $request->headers->get('content-disposition'))) { throw new BadRequestHttpException('"Content-Disposition" header is required. A file name in the format "filename=FILENAME" must be provided.'); } - $content_disposition = $request->headers->get('content-disposition'); - // Parse the header value. This regex does not allow an empty filename. // i.e. 'filename=""'. This also matches on a word boundary so other keys // like 'not_a_filename' don't work. diff --git a/tests/src/Functional/FileUploadTest.php b/tests/src/Functional/FileUploadTest.php index 00b81fe..94d93bd 100644 --- a/tests/src/Functional/FileUploadTest.php +++ b/tests/src/Functional/FileUploadTest.php @@ -747,6 +747,8 @@ class FileUploadTest extends ResourceTestBase { 'Content-Type' => 'application/octet-stream', // Set the required Content-Disposition header for the file name. 'Content-Disposition' => 'file; filename="example.txt"', + // Set the required JSON:API Accept header. + 'Accept' => 'application/vnd.api+json', ]; $request_options[RequestOptions::BODY] = $file_contents; $request_options = NestedArray::mergeDeep($request_options, $this->getAuthenticationRequestOptions());