1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Use stream when downloading documents

This commit is contained in:
Joshua Dwire 2016-03-23 20:46:09 -04:00
parent ae6fa5ab9b
commit 10fa256809
2 changed files with 22 additions and 3 deletions

View File

@ -38,10 +38,23 @@ class DocumentController extends BaseController
return redirect($direct_url);
}
$stream = $document->getStream();
$response = Response::make($document->getRaw(), 200);
$response->header('content-type', $document->type);
if($stream){
$headers = [
'Content-Type' => $document->type,
'Content-Length' => $document->size,
];
$response = Response::stream(function() use ($stream) {
fpassthru($stream);
}, 200, $headers);
}
else{
$response = Response::make($document->getRaw(), 200);
$response->header('content-type', $document->type);
}
return $response;
}

View File

@ -122,6 +122,12 @@ class Document extends EntityModel
return $disk->get($this->path);
}
public function getStream(){
$disk = $this->getDisk();
return $disk->readStream($this->path);
}
public function getRawPreview(){
$disk = $this->getDisk();