Skip to content

Commit

Permalink
fix: 修复本地模式无法访问到图片的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
mouyong committed Jan 3, 2025
1 parent c1dfe6c commit 0b71fb7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions FileStorage/app/Utilities/FileUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ public static function getStorage(): FilesystemAdapter
return Storage::disk($disk);
}

public static function getImageUrl($path)
{
$httpOrigin = request()->server('HTTP_ORIGIN');
$finalUrl = $httpOrigin . $path;
return $finalUrl;
}

public static function buildLocalTemporaryUrls()
{
$disk = FileUtility::initConfig();
Expand All @@ -152,7 +159,8 @@ function (string $path, DateTime $expiration, array $options) {
return URL::temporarySignedRoute(
'file.download',
$expiration,
array_merge($options, ['action' => 'view', 'filename' => $filename, 'extension' => $extension, 'path' => $path])
array_merge($options, ['action' => 'view', 'filename' => $filename, 'extension' => $extension, 'path' => $path]),
true,
);
}
);
Expand All @@ -169,10 +177,6 @@ public static function handleFileWithAction($action, $path)
/** @var FilesystemAdapter */
$storage = Storage::disk($disk);

if ($disk == 'local') {
$path = "public/$path";
}

if (!$storage->has($path)) {
return null;
}
Expand Down

0 comments on commit 0b71fb7

Please sign in to comment.