diff --git a/lib/Service/Attachment/AttachmentService.php b/lib/Service/Attachment/AttachmentService.php index 6bc208de3e..64eab72a79 100644 --- a/lib/Service/Attachment/AttachmentService.php +++ b/lib/Service/Attachment/AttachmentService.php @@ -82,6 +82,10 @@ public function addFile(string $userId, UploadedFile $file): LocalAttachment { $attachment->setMimeType($file->getMimeType()); $persisted = $this->mapper->insert($attachment); + if ($persisted->id === null) { + throw new UploadException('Given attachmentId is null'); + } + try { $this->storage->save($userId, $persisted->id, $file); } catch (UploadException $ex) { @@ -100,6 +104,10 @@ public function addFileFromString(string $userId, string $name, string $mime, st $attachment->setMimeType($mime); $persisted = $this->mapper->insert($attachment); + if ($persisted->id === null) { + throw new UploadException('Given attachmentId is null'); + } + try { $this->storage->saveContent($userId, $persisted->id, $fileContents); } catch (NotFoundException|NotPermittedException $e) { diff --git a/lib/Service/Attachment/AttachmentStorage.php b/lib/Service/Attachment/AttachmentStorage.php index 94853dd1cf..b5eb6acab3 100644 --- a/lib/Service/Attachment/AttachmentStorage.php +++ b/lib/Service/Attachment/AttachmentStorage.php @@ -48,14 +48,14 @@ private function getAttachmentFolder($userId): ISimpleFolder { * Copy uploaded file content to a app data file * * @param string $userId - * @param int $attachmentId + * @param int|string $attachmentId * @param UploadedFile $uploadedFile * * @throws UploadException * * @return void */ - public function save(string $userId, int $attachmentId, UploadedFile $uploadedFile): void { + public function save(string $userId, int|string $attachmentId, UploadedFile $uploadedFile): void { $folder = $this->getAttachmentFolder($userId); $file = $folder->newFile((string)$attachmentId); @@ -80,12 +80,12 @@ public function save(string $userId, int $attachmentId, UploadedFile $uploadedFi * Copy uploaded file content to a app data file * * @param string $userId - * @param int $attachmentId + * @param int|string $attachmentId * * @return void * @throws NotFoundException|NotPermittedException */ - public function saveContent(string $userId, int $attachmentId, string $fileContent): void { + public function saveContent(string $userId, int|string $attachmentId, string $fileContent): void { $folder = $this->getAttachmentFolder($userId); $file = $folder->newFile((string)$attachmentId); $file->putContent($fileContent);