Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulien Veyssier <eneiluj@posteo.net>2021-12-28 18:16:24 +0300
committerJulien Veyssier <eneiluj@posteo.net>2022-01-03 12:27:39 +0300
commitef8358be6d3d1ad1ee7007d3f092e033d6613f64 (patch)
treeb2b4dd5df0ebcb76544e6575ae1177f2aef2a181 /lib
parent7eaf9d661f8b3734eded14b0ed90325bfa7e176a (diff)
stream uploaded file to the storage with a resource
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ImageController.php8
-rw-r--r--lib/Service/ImageService.php8
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(),