Loading src/Controller/S3fsImageStyleDownloadController.php +3 −2 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\s3fs\Controller; use Drupal\Component\Utility\Crypt; use Drupal\Core\Cache\Cache; use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\StreamWrapper\StreamWrapperManager; use Drupal\image\Controller\ImageStyleDownloadController; use Drupal\image\ImageStyleInterface; use Symfony\Component\HttpFoundation\Request; Loading Loading @@ -79,8 +80,8 @@ class S3fsImageStyleDownloadController extends ImageStyleDownloadController { // original file, resulting in filenames like image.png.jpeg. So to find // the actual source image, we remove the extension and check if that // image exists. $path_info = pathinfo($image_uri); $converted_image_uri = $path_info['dirname'] . DIRECTORY_SEPARATOR . $path_info['filename']; $path_info = pathinfo(StreamWrapperManager::getTarget($image_uri)); $converted_image_uri = sprintf('%s://%s/%s', $this->streamWrapperManager->getScheme($derivative_uri), $path_info['dirname'], $path_info['filename']); if (!file_exists($converted_image_uri)) { $this->logger->notice('Source image at %source_image_path not found while trying to generate derivative image at %derivative_path.', [ Loading tests/src/Functional/S3fsTest.php +37 −0 Original line number Diff line number Diff line Loading @@ -203,6 +203,43 @@ class S3fsTest extends S3fsTestBase { } /** * Tests that files stored in the root folder are converted properly. * * Imported from core. */ public function testConvertFileInRoot() { // Create the test image style with a Convert effect. $image_style = ImageStyle::create([ 'name' => 'image_effect_test', 'label' => 'Image Effect Test', ]); $this->assertEquals(SAVED_NEW, $image_style->save()); $image_style->addImageEffect([ 'id' => 'image_convert', 'data' => [ 'extension' => 'jpeg', ], ]); $this->assertEquals(SAVED_UPDATED, $image_style->save()); // Create a copy of a test image file in root. $test_uri = 's3://image-test-do.png'; $img_localpath = __DIR__ . '/../../fixtures/test.png'; $img_data = file_get_contents($img_localpath); $this->saveData($img_data, $test_uri); $this->assertFileExists($test_uri); // Execute the image style on the test image via a GET request. $derivative_uri = 's3://styles/image_effect_test/s3/image-test-do.png.jpeg'; $this->assertFileDoesNotExist($derivative_uri); $style_url_parsed = UrlHelper::parse(ImageStyle::load('image_effect_test')->buildUrl($test_uri)); $this->drupalGet($style_url_parsed['path'], ['query' => $style_url_parsed['query']]); $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($derivative_uri); } /** * Test the cache refresh. */ Loading Loading
src/Controller/S3fsImageStyleDownloadController.php +3 −2 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\s3fs\Controller; use Drupal\Component\Utility\Crypt; use Drupal\Core\Cache\Cache; use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\StreamWrapper\StreamWrapperManager; use Drupal\image\Controller\ImageStyleDownloadController; use Drupal\image\ImageStyleInterface; use Symfony\Component\HttpFoundation\Request; Loading Loading @@ -79,8 +80,8 @@ class S3fsImageStyleDownloadController extends ImageStyleDownloadController { // original file, resulting in filenames like image.png.jpeg. So to find // the actual source image, we remove the extension and check if that // image exists. $path_info = pathinfo($image_uri); $converted_image_uri = $path_info['dirname'] . DIRECTORY_SEPARATOR . $path_info['filename']; $path_info = pathinfo(StreamWrapperManager::getTarget($image_uri)); $converted_image_uri = sprintf('%s://%s/%s', $this->streamWrapperManager->getScheme($derivative_uri), $path_info['dirname'], $path_info['filename']); if (!file_exists($converted_image_uri)) { $this->logger->notice('Source image at %source_image_path not found while trying to generate derivative image at %derivative_path.', [ Loading
tests/src/Functional/S3fsTest.php +37 −0 Original line number Diff line number Diff line Loading @@ -203,6 +203,43 @@ class S3fsTest extends S3fsTestBase { } /** * Tests that files stored in the root folder are converted properly. * * Imported from core. */ public function testConvertFileInRoot() { // Create the test image style with a Convert effect. $image_style = ImageStyle::create([ 'name' => 'image_effect_test', 'label' => 'Image Effect Test', ]); $this->assertEquals(SAVED_NEW, $image_style->save()); $image_style->addImageEffect([ 'id' => 'image_convert', 'data' => [ 'extension' => 'jpeg', ], ]); $this->assertEquals(SAVED_UPDATED, $image_style->save()); // Create a copy of a test image file in root. $test_uri = 's3://image-test-do.png'; $img_localpath = __DIR__ . '/../../fixtures/test.png'; $img_data = file_get_contents($img_localpath); $this->saveData($img_data, $test_uri); $this->assertFileExists($test_uri); // Execute the image style on the test image via a GET request. $derivative_uri = 's3://styles/image_effect_test/s3/image-test-do.png.jpeg'; $this->assertFileDoesNotExist($derivative_uri); $style_url_parsed = UrlHelper::parse(ImageStyle::load('image_effect_test')->buildUrl($test_uri)); $this->drupalGet($style_url_parsed['path'], ['query' => $style_url_parsed['query']]); $this->assertSession()->statusCodeEquals(200); $this->assertFileExists($derivative_uri); } /** * Test the cache refresh. */ Loading