|
5 | 5 | use BookStack\Util\FilePathNormalizer; |
6 | 6 | use Illuminate\Contracts\Filesystem\Filesystem; |
7 | 7 | use Illuminate\Filesystem\FilesystemAdapter; |
| 8 | +use Illuminate\Support\Facades\Log; |
| 9 | +use League\Flysystem\UnableToSetVisibility; |
8 | 10 | use Symfony\Component\HttpFoundation\StreamedResponse; |
9 | 11 |
|
10 | 12 | class ImageStorageDisk |
@@ -74,12 +76,19 @@ public function put(string $path, string $data, bool $makePublic = false): void |
74 | 76 | $path = $this->adjustPathForDisk($path); |
75 | 77 | $this->filesystem->put($path, $data); |
76 | 78 |
|
77 | | - // Set visibility when a non-AWS-s3, s3-like storage option is in use. |
78 | | - // Done since this call can break s3-like services but desired for other image stores. |
79 | | - // Attempting to set ACL during above put request requires different permissions |
80 | | - // hence would technically be a breaking change for actual s3 usage. |
| 79 | + // Set public visibility to ensure public access on S3, or that the file is accessible |
| 80 | + // to other processes (like web-servers) for local file storage options. |
| 81 | + // We avoid attempting this for (non-AWS) s3-like systems (even in a try-catch) as |
| 82 | + // we've always avoided setting permissions for s3-like due to potential issues, |
| 83 | + // with docs advising setting pre-configured permissions instead. |
| 84 | + // We also don't do this as the default filesystem/driver level as that can technically |
| 85 | + // require different ACLs for S3, and this provides us more logical control. |
81 | 86 | if ($makePublic && !$this->isS3Like()) { |
82 | | - $this->filesystem->setVisibility($path, 'public'); |
| 87 | + try { |
| 88 | + $this->filesystem->setVisibility($path, 'public'); |
| 89 | + } catch (UnableToSetVisibility $e) { |
| 90 | + Log::warning("Unable to set visibility for image upload with relative path: {$path}"); |
| 91 | + } |
83 | 92 | } |
84 | 93 | } |
85 | 94 |
|
|
0 commit comments