Skip to content

Commit

Permalink
Merge pull request #550 from juliushaertl/bugfix/noid/memory-file-con…
Browse files Browse the repository at this point in the history
…tent

Do not load the full file content into memory
  • Loading branch information
LinneyS authored Feb 9, 2022
2 parents a0f8b6b + cf06f67 commit 4b4bc04
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\StreamResponse;
use OCP\AppFramework\QueryException;
use OCP\Files\File;
use OCP\Files\Folder;
Expand Down Expand Up @@ -177,7 +178,7 @@ public function __construct($AppName,
*
* @param string $doc - verification token with the file identifier
*
* @return DataDownloadResponse|JSONResponse
* @return StreamResponse|JSONResponse
*
* @NoAdminRequired
* @NoCSRFRequired
Expand Down Expand Up @@ -294,7 +295,10 @@ public function download($doc) {
}

try {
return new DataDownloadResponse($file->getContent(), $file->getName(), $file->getMimeType());
$response = new StreamResponse($file->fopen('rb'));
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($file->getName()) . '"');
$response->addHeader('Content-Type', $file->getMimeType());
return $response;
} catch (NotPermittedException $e) {
$this->logger->logException($e, ["message" => "Download Not permitted: $fileId ($version)", "app" => $this->appName]);
return new JSONResponse(["message" => $this->trans->t("Not permitted")], Http::STATUS_FORBIDDEN);
Expand Down

0 comments on commit 4b4bc04

Please sign in to comment.