diff options
-rw-r--r-- | lib/Controller/ImageController.php | 8 | ||||
-rw-r--r-- | lib/Service/ImageService.php | 8 |
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/Controller/ImageController.php b/lib/Controller/ImageController.php index 508a4e34b..e0ce77e42 100644 --- a/lib/Controller/ImageController.php +++ b/lib/Controller/ImageController.php @@ -166,13 +166,17 @@ class ImageController extends Controller { return new DataResponse(['error' => 'Image type not supported'], Http::STATUS_BAD_REQUEST); } $newFileContent = file_get_contents($file['tmp_name']); + $newFileResource = fopen($file['tmp_name'], 'rb'); + if ($newFileResource === false) { + throw new Exception('Could not read file'); + } $newFileName = $file['name']; if ($shareToken) { - $uploadResult = $this->imageService->uploadImagePublic($documentId, $newFileName, $newFileContent, $shareToken); + $uploadResult = $this->imageService->uploadImagePublic($documentId, $newFileName, $newFileResource, $shareToken); } else { $session = $this->sessionService->getSession($documentId, $sessionId, $sessionToken); $userId = $session->getUserId(); - $uploadResult = $this->imageService->uploadImage($documentId, $newFileName, $newFileContent, $userId); + $uploadResult = $this->imageService->uploadImage($documentId, $newFileName, $newFileResource, $userId); } return new DataResponse($uploadResult); } diff --git a/lib/Service/ImageService.php b/lib/Service/ImageService.php index 2afd339bc..8cd80b308 100644 --- a/lib/Service/ImageService.php +++ b/lib/Service/ImageService.php @@ -147,14 +147,14 @@ class ImageService { * @throws \OCP\Files\InvalidPathException * @throws \OC\User\NoUserException */ - public function uploadImage(int $documentId, string $newFileName, string $newFileContent, string $userId): array { + public function uploadImage(int $documentId, string $newFileName, $newFileResource, string $userId): array { $textFile = $this->getTextFile($documentId, $userId); if (!$textFile->isUpdateable()) { throw new NotPermittedException('No write permissions'); } $saveDir = $this->getAttachmentDirectoryForFile($textFile, true); $fileName = (string) time() . '-' . $newFileName; - $savedFile = $saveDir->newFile($fileName, $newFileContent); + $savedFile = $saveDir->newFile($fileName, $newFileResource); return [ 'name' => $fileName, 'id' => $savedFile->getId(), @@ -174,14 +174,14 @@ class ImageService { * @throws \OCP\Files\InvalidPathException * @throws \OC\User\NoUserException */ - public function uploadImagePublic(?int $documentId, string $newFileName, string $newFileContent, string $shareToken): array { + public function uploadImagePublic(?int $documentId, string $newFileName, $newFileResource, string $shareToken): array { if (!$this->hasUpdatePermissions($shareToken)) { throw new NotPermittedException('No write permissions'); } $textFile = $this->getTextFilePublic($documentId, $shareToken); $saveDir = $this->getAttachmentDirectoryForFile($textFile, true); $fileName = (string) time() . '-' . $newFileName; - $savedFile = $saveDir->newFile($fileName, $newFileContent); + $savedFile = $saveDir->newFile($fileName, $newFileResource); return [ 'name' => $fileName, 'id' => $savedFile->getId(), |