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:
parent
ae6fa5ab9b
commit
10fa256809
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user