fixed S3 download functionality

This commit is contained in:
ak 2023-10-21 10:45:32 -07:00
parent 85db96ed37
commit e68158aef2

View file

@ -457,20 +457,10 @@ class FileController extends Controller
else { else {
// create a new path // create a new path
$path = pathinfo($file->stored_at, PATHINFO_BASENAME); $path = pathinfo($file->stored_at, PATHINFO_BASENAME);
// if file has been uploaded to S3, // pull the file off S3
if ($file->s3 == 1) { $s3file = Storage::disk('s3')->get($file->stored_at);
// pull the file off S3 // put it on the public drive for use
$s3file = Storage::get($file->stored_at); Storage::disk('public')->put($path, $s3file);
// put it on the public drive for use
Storage::disk('public')->put($path, $s3file);
} else {
// modify path
$path = 'public/' . $path;
// get local file
$localFile = Storage::disk('local')->get($file->stored_at);
// put it on the public drive for use
Storage::disk('public')->put($path, $localFile);
}
// define download path as being the file on the public drive // define download path as being the file on the public drive
$downloadURL = asset(Storage::disk('public')->url($path)); $downloadURL = asset(Storage::disk('public')->url($path));
// define filename // define filename
@ -538,20 +528,10 @@ class FileController extends Controller
else { else {
// create a new path // create a new path
$path = pathinfo($file->stored_at, PATHINFO_BASENAME); $path = pathinfo($file->stored_at, PATHINFO_BASENAME);
// if file has been uploaded to S3, // pull the file off S3
if ($file->s3 == 1) { $s3file = Storage::disk('s3')->get($file->stored_at);
// pull the file off S3 // put it on the public drive for use
$s3file = Storage::get($file->stored_at); Storage::disk('public')->put($path, $s3file);
// put it on the public drive for use
Storage::disk('public')->put($path, $s3file);
} else {
// modify path
$path = 'public/' . $path;
// get local file
$localFile = Storage::disk('local')->get($file->stored_at);
// put it on the public drive for use
Storage::disk('public')->put($path, $localFile);
}
// define download path as being the file on the public drive // define download path as being the file on the public drive
$downloadURL = asset(Storage::disk('public')->url($path)); $downloadURL = asset(Storage::disk('public')->url($path));
// define filename // define filename
@ -608,22 +588,12 @@ class FileController extends Controller
} }
// otherwise // otherwise
else { else {
// create a new path off // create a new path
$path = pathinfo($file->stored_at, PATHINFO_BASENAME); $path = pathinfo($file->stored_at, PATHINFO_BASENAME);
// if file has been uploaded to S3, // pull the file off S3
if ($file->s3 == 1) { $s3file = Storage::disk('s3')->get($file->stored_at);
// pull the file off S3 // put it on the public drive for use
$s3file = Storage::get($file->stored_at); Storage::disk('public')->put($path, $s3file);
// put it on the public drive for use
Storage::disk('public')->put($path, $s3file);
} else {
// modify path
$path = 'public/' . $path;
// get local file
$localFile = Storage::disk('local')->get($file->stored_at);
// put it on the public drive for use
Storage::disk('public')->put($path, $localFile);
}
// define download path as being the file on the public drive // define download path as being the file on the public drive
$downloadURL = asset(Storage::disk('public')->url($path)); $downloadURL = asset(Storage::disk('public')->url($path));
// define filename // define filename
@ -692,20 +662,10 @@ class FileController extends Controller
else { else {
// create a new path // create a new path
$path = pathinfo($file->stored_at, PATHINFO_BASENAME); $path = pathinfo($file->stored_at, PATHINFO_BASENAME);
// if file has been uploaded to S3, // pull the file off S3
if ($file->s3 == 1) { $s3file = Storage::disk('s3')->get($file->stored_at);
// pull the file off S3 // put it on the public drive for use
$s3file = Storage::get($file->stored_at); Storage::disk('public')->put($path, $s3file);
// put it on the public drive for use
Storage::disk('public')->put($path, $s3file);
} else {
// modify path
$path = 'public/' . $path;
// get local file
$localFile = Storage::disk('local')->get($file->stored_at);
// put it on the public drive for use
Storage::disk('public')->put($path, $localFile);
}
// define download path as being the file on the public drive // define download path as being the file on the public drive
$downloadURL = asset(Storage::disk('public')->url($path)); $downloadURL = asset(Storage::disk('public')->url($path));
// define filename // define filename
@ -762,22 +722,12 @@ class FileController extends Controller
} }
// otherwise // otherwise
else { else {
// create a new path off "public/" // create a new path
$path = pathinfo($file->stored_at, PATHINFO_BASENAME); $path = pathinfo($file->stored_at, PATHINFO_BASENAME);
// if file has been uploaded to S3, // pull the file off S3
if ($file->s3 == 1) { $s3file = Storage::disk('s3')->get($file->stored_at);
// pull the file off S3 // put it on the public drive for use
$s3file = Storage::get($file->stored_at); Storage::disk('public')->put($path, $s3file);
// put it on the public drive for use
Storage::disk('public')->put($path, $s3file);
} else {
// modify path
$path = 'public/' . $path;
// get local file
$localFile = Storage::disk('local')->get($file->stored_at);
// put it on the public drive for use
Storage::disk('public')->put($path, $localFile);
}
// define download path as being the file on the public drive // define download path as being the file on the public drive
$downloadURL = asset(Storage::disk('public')->url($path)); $downloadURL = asset(Storage::disk('public')->url($path));
// define filename // define filename
@ -1076,20 +1026,14 @@ class FileController extends Controller
if ($file->children->isEmpty()) { if ($file->children->isEmpty()) {
// set $internalPath to reflect file // set $internalPath to reflect file
$internalPath = $parent . $file->name; $internalPath = $parent . $file->name;
// default file path is stored on local storage // create a new path
$filePath = Storage::disk('local')->path($file->stored_at); $filePath = pathinfo($file->stored_at, PATHINFO_BASENAME);
// pull the file off S3
// if the file is uploaded to S3 $s3file = Storage::disk('s3')->get($file->stored_at);
if ($file->s3 == 1) { // put it on the public drive for use
// create a new path Storage::disk('public')->put($filePath, $s3file);
$filePath = pathinfo($file->stored_at, PATHINFO_BASENAME); // reassign $filePath to the actual file path
// pull the file off S3 $filePath = Storage::disk('public')->path($filePath);
$s3file = Storage::get($file->stored_at);
// put it on the public drive for use
Storage::disk('public')->put($filePath, $s3file);
// reassign $filePath to the actual file path
$filePath = Storage::disk('public')->path($filePath);
}
// add file to archive // add file to archive
$archive->addFile($filePath, $internalPath); $archive->addFile($filePath, $internalPath);