My s3fs.use_s3_for_public setting is "false". My understanding (please correct me if I'm wrong) is that the S3 module should not create copies of files in S3 with this setting set to false. We specifically want these generated files stored locally on the Drupal instance so that we can rewrite them to hit a CDN, along with our CSS and Javascript.

My listing (view) page renders my "report" content type using the "teaser" display mode. For this display mode the "attachment thumbnail" field is rendered with format "thumbnail" and the image style is "report_cover".

The rendered link in the source is like: <img src="/s3/files/styles/report_cover/s3/import/myimage.jpg?itok=e2a6TMam" width="165" height="220" alt="Thumbnail" title="myimage.jpg" typeof="foaf:Image" /> I'm 90% sure this is just how core ImageStyle::buildUri() is going to build URL's for styled images when the scheme is S3, but again please correct me if I'm wrong.

s3fs.services.yml and S3fsPathProcessorImageStyles mean that we'll always use S3fsImageStyleDownloadController::deliver() instead of the core ImageStyleDownloadController::deliver() for these URL's.

The actual bug: S3fsImageStyleDownloadController will always create a copy (the style generated image) in S3, regardless of the s3fs.use_s3_for_public setting setting.

I've attached a patch that seems to fix this issue my side; it might be nicer to just fall back to the core ImageStyleDownloadController when s3fs.use_s3_for_public setting is false? I haven't checked, but I think it might just work when the source image is at an s3:// scheme, since that should use the s3fs stream wrapper.

Comments

George Bills created an issue. See original summary.

jansete’s picture

Status: Active » Closed (works as designed)

Hi @George Bills, this works as designed, there are different combinations:
- Use S3 for all public files (using public://) s3fs.use_s3_for_public = TRUE
- Use S3 for specified fields (like your example) s3fs.use_s3_for_public = FALSE and field config mark as "S3" in file storage settings
- Use local file system, Field storage marked as "public" and s3fs.use_s3_for_public = FALSE

/s3/files/styles/report_cover/s3/import/myimage.jpg?itok=e2a6TMam

The URL pattern of the route is:
/s3/files/styles/{image_style}/{scheme}

In your case scheme is marked as "S3" this is the reason that the images is generated in S3, if you use public storage in field settings and put with s3fs.use_s3_for_public = FALSE, image style will be generated in your local file system.