diff --git a/src/ImageWrapper.php b/src/ImageWrapper.php index d714dd3..55afd44 100644 --- a/src/ImageWrapper.php +++ b/src/ImageWrapper.php @@ -3,6 +3,7 @@ use Illuminate\Http\Response; use Knp\Snappy\Image as SnappyImage; use Illuminate\Support\Facades\View; +use Illuminate\Support\Facades\Storage; use Symfony\Component\HttpFoundation\StreamedResponse; /** @@ -137,10 +138,11 @@ public function save($filename, $overwrite = false) */ public function download($filename = 'image.jpg') { - return new Response($this->output(), 200, array( - 'Content-Type' => 'image/jpeg', - 'Content-Disposition' => 'attachment; filename="'.$filename.'"' - )); + Storage::put($filename, $this->output()); + + return response() + ->download(Storage::path('/').$filename) + ->deleteFileAfterSend(); } /** diff --git a/src/PdfWrapper.php b/src/PdfWrapper.php index 53accec..bee9eab 100644 --- a/src/PdfWrapper.php +++ b/src/PdfWrapper.php @@ -3,6 +3,7 @@ use Illuminate\Http\Response; use Knp\Snappy\Pdf as SnappyPDF; use Illuminate\Support\Facades\View; +use Illuminate\Support\Facades\Storage; use Illuminate\Contracts\Support\Renderable; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -213,10 +214,11 @@ public function save($filename, $overwrite = false) */ public function download($filename = 'document.pdf') { - return new Response($this->output(), 200, array( - 'Content-Type' => 'application/pdf', - 'Content-Disposition' => 'attachment; filename="'.$filename.'"' - )); + Storage::put($filename, $this->output()); + + return response() + ->download(Storage::path('/').$filename) + ->deleteFileAfterSend(); } /**