- * Save image data for the given path in the public space, if possible,
- * for the provided storage mechanism.
- */
- protected function saveImageDataInPublicSpace(Storage $storage, string $path, string $data)
- {
- $storage->put($path, $data);
-
- // Set visibility when a non-AWS-s3, s3-like storage option is in use.
- // Done since this call can break s3-like services but desired for other image stores.
- // Attempting to set ACL during above put request requires different permissions
- // hence would technically be a breaking change for actual s3 usage.
- $usingS3 = strtolower(config('filesystems.images')) === 's3';
- $usingS3Like = $usingS3 && !is_null(config('filesystems.disks.s3.endpoint'));
- if (!$usingS3Like) {
- $storage->setVisibility($path, 'public');
- }
- }
-
- /**
- * Clean up an image file name to be both URL and storage safe.
- */
- protected function cleanImageFileName(string $name): string
- {
- $name = str_replace(' ', '-', $name);
- $nameParts = explode('.', $name);
- $extension = array_pop($nameParts);
- $name = implode('-', $nameParts);
- $name = Str::slug($name);
-
- if (strlen($name) === 0) {
- $name = Str::random(10);
- }
-
- return $name . '.' . $extension;
- }
-
- /**
- * Checks if the image is a gif. Returns true if it is, else false.