Merge pull request #2970 from novag/inline
add 'inline' route to allow embedding uploads
This commit is contained in:
commit
dbd2589c61
@ -34,6 +34,22 @@ class Uploads extends Controller
|
|||||||
return $this->streamMedia($media);
|
return $this->streamMedia($media);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function inline($id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$media = Media::find($id);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return response(null, 204);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get file path
|
||||||
|
if (!$this->getMediaPathOnStorage($media)) {
|
||||||
|
return response(null, 204);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->streamMedia($media, 'inline');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the specified resource.
|
* Get the specified resource.
|
||||||
*
|
*
|
||||||
|
@ -118,7 +118,7 @@ trait Uploads
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function streamMedia($media)
|
public function streamMedia($media, $disposition = 'attachment')
|
||||||
{
|
{
|
||||||
return response()->streamDownload(
|
return response()->streamDownload(
|
||||||
function() use ($media) {
|
function() use ($media) {
|
||||||
@ -133,6 +133,7 @@ trait Uploads
|
|||||||
'Content-Type' => $media->mime_type,
|
'Content-Type' => $media->mime_type,
|
||||||
'Content-Length' => $media->size,
|
'Content-Length' => $media->size,
|
||||||
],
|
],
|
||||||
|
$disposition,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Route;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Route::group(['as' => 'uploads.', 'prefix' => 'uploads'], function () {
|
Route::group(['as' => 'uploads.', 'prefix' => 'uploads'], function () {
|
||||||
|
Route::get('{id}/inline', 'Common\Uploads@inline')->name('inline');
|
||||||
Route::delete('{id}', 'Common\Uploads@destroy')->name('destroy');
|
Route::delete('{id}', 'Common\Uploads@destroy')->name('destroy');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user