return $file->view();
}
+ public function download(PdfFile $file, Request $request)
+ {
+ if (! $request->hasValidSignature()) {
+ abort(401);
+ }
+ return $file->downloadFile();
+ }
+
}
use A17\Twill\Models\Behaviors\Sortable;
use A17\Twill\Models\Model as TwillModel;
use App\Flowpaper\Pdf2Json;
+use Aws\S3\S3Client;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
}
+ /**
+ * @param false $download
+ * @return \Symfony\Component\HttpFoundation\StreamedResponse
+ */
+ public function downloadFile($download = false)
+ {
+ $disposition = $download ?
+ 'attachment' :
+ 'inline';
+ $fs = Storage::cloud()->getDriver();
+ $stream = $fs->readStream($this->binPath);
+ return \Response::stream(function() use ($stream) {
+ fpassthru($stream);
+ }, 200, [
+ 'Content-Type' => 'application/pdf',
+ 'Content-Length' => $fs->getSize($this->binPath),
+ 'Content-Disposition' => sprintf('%s; filename="%s.pdf"', $disposition, $this->title),
+ ]);
+ }
/**
->get('/view/{file:slug}', 'FlowpaperController@view')
->name('flowpaper.view');
- //For discover users
- Route::get('/discover/{file:slug}', 'FlowpaperController@discover')->name('flowpaper.discover');
- //For admin preview
- Route::get('/preview/{file:slug}', 'FlowpaperController@preview')->name('flowpaper.preview');
+ Route::get('edition/{file:slug}', 'FileController@show');
+ /** For discover users */
+ Route::get('discover/{file:slug}', 'FlowpaperController@discover')->name('flowpaper.discover');
+ /** For admin preview */
+ Route::get('preview/{file:slug}', 'FlowpaperController@preview')->name('flowpaper.preview');
+ /** Download file */
+ Route::get('download/{file:slug}', 'FlowpaperController@download')->name('pdf.download');
- Route::get('edition/{file:slug}', 'FileController@show');
Route::get('search', 'FileController@search')->name('archives');