Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Craft 5] Google Cloud Storage and IMGix not using Asset Volume Subpath in transform URL #403

Closed
robzor opened this issue Apr 30, 2024 · 9 comments
Labels

Comments

@robzor
Copy link

robzor commented Apr 30, 2024

Question

Hi there,

I have 1 Filesystem (a Google Cloud Storage bucket) and 4 Image Volumes.

Each volume has a Subpath set, e.g. for Hero Images I have images-hero set as the Subpath.

I have configured ImageOptimize to use the IMGix transformer but the URL to the uploaded images is missing the Subpath.

For example, if I go to the Assets folder view, the URL to an asset is:

https://storage.googleapis.com/<cloudstorage-bucket-name>/images-hero/example-image.jpg

but if i view the thumbnail, for example, the URL to the thumbnail image is:

https://<imgix source domain>.imgix.net/example-image.jpg?auto=compress%2Cformat&crop=focalpoint&domain=cla-website-dev.imgix.net&fit=crop&fp-x=0.5&fp-y=0.5&h=12&ixlib=php-3.3.1&w=30

And this image does not display, because it is missing the Subpath from the path.

As a test, If I manually add /images-hero/ to the above URL after the source domain, I can see the transformed Asset successfully generated by IMGix.

Is this a bug with ImageOptimize or a configuration issue on my end?

Thanks in advance for any help you can give!

EDIT:

I can't seem to find this actually documented anywhere, but in Craft 5, you can have a 1:many Filesystem > Volume setup, so I think this is actually a bug! The key field here is Subpath in the Volume settings:

CleanShot 2024-04-30 at 3  38 04 2

Additional context

Craft CMS 5.0.5
ImageOptimize 5.0.0

@robzor robzor changed the title Google Cloud Storage and IMGix not using Asset Volume Subpath in transform URL [Craft 5] Google Cloud Storage and IMGix not using Asset Volume Subpath in transform URL Apr 30, 2024
@khalwat
Copy link
Contributor

khalwat commented May 2, 2024

I think this might be a bug

@robzor
Copy link
Author

robzor commented May 2, 2024

I agree! I'm hoping it's easy for you to add the Sub Path to the output URL?

@robzor
Copy link
Author

robzor commented May 8, 2024

Hi @khalwat any update on this? It's currently a blocker for showing the client some of our development work.

If you need any further information to help with debugging, let me know :)

Thanks!

@khalwat
Copy link
Contributor

khalwat commented May 8, 2024

So I have been looking into it, the strange thing is it does look like the code takes into account the subfolder setting:

        // Account for volume types with a subfolder setting
        // e.g. craftcms/aws-s3, craftcms/google-cloud
        if ($volume->getFs()->subfolder ?? null) {
            $subfolder = $volume->getFs()->subfolder;
            $subfolder = Craft::parseEnv($subfolder);
            return rtrim($subfolder, '/') . '/' . $assetPath;
        }

So I'm a little confused as to why this is not working already.

@khalwat
Copy link
Contributor

khalwat commented May 8, 2024

Any chance we can do a quick video conf to check out your setup and perhaps put in some debug code to see what's going on?

https://savvycal.com/nystudio107/chat

@robzor
Copy link
Author

robzor commented May 8, 2024

Hi Andrew,

Unfortunately we're in different timezones, and I was out when your message came through.

I think the difference here is that it's not a subfolder, it's a sub path

return FileHelper::normalizePath($fs->getRootPath() . DIRECTORY_SEPARATOR . $volume->getSubpath() . $this->getPath());

Sorry for the formatting I'm replying on my phone but I think getSubpath() is the thing here. (This is from src/elements/Asset.php).

@robzor
Copy link
Author

robzor commented May 8, 2024

Any chance we can do a quick video conf to check out your setup and perhaps put in some debug code to see what's going on?

https://savvycal.com/nystudio107/chat

Ahh my bad I didn't realise this was a scheduling app, I'll put in some availability for you.

khalwat added a commit that referenced this issue May 9, 2024
@khalwat
Copy link
Contributor

khalwat commented May 9, 2024

Fixed in the above commit.

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-imageoptimize": "dev-develop-v5 as 5.0.1”,

Then do a composer clear-cache && composer update

@khalwat khalwat closed this as completed May 9, 2024
@robzor
Copy link
Author

robzor commented May 9, 2024

That's working for me in the control panel now, thumbnails and transformed images are showing up in the IO field and it's working on the front end too. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants