id === null) { throw new BadRequestException('id is required'); } if ( $request->fileContents === null || $request->fileOriginalName === null || $request->fileMimeType === null || $request->fileSizeBytes === null ) { throw new BadRequestException('pdf is required'); } if ( ! in_array( $request->fileMimeType, self::ALLOWED_MIME_TYPES, true, ) ) { throw new BadRequestException('pdf must be a pdf file'); } if ($request->fileSizeBytes > self::MAX_SIZE_BYTES) { throw new BadRequestException('pdf must be 10MB or smaller'); } $element = $this->elementRepository->find($request->id); if ($element === null) { throw new NotFoundException('Element not found'); } $pdf = new FileToUpload( contents: $request->fileContents, originalName: $request->fileOriginalName, mimeType: $request->fileMimeType, sizeBytes: $request->fileSizeBytes, ); $path = $this->fileUploader->upload($pdf, 'element-pdfs/long'); $element->setLongPdfPath($path); return $this->elementRepository->update($element); } }