verbb / image-resizer

A Craft CMS plugin to resize images on upload.
MIT License
128 stars 14 forks source link

When uploading an image with a filename that already exists, and chosing "rename", image-resizer errors #79

Open jamie-s-white opened 1 year ago

jamie-s-white commented 1 year ago

Describe the bug

When uploading an image with a filename that already exists, and chosing "rename", image-resizer errors

Steps to reproduce

  1. Upload a file named "test-image-6.jpg", image-resizer correctly handles the file
  2. Upload a second file named "test-image-6.jpg".
  3. Choose "rename" when Craft CMS asks
  4. Image-resizer has not resized this image
  5. In the logs, we have: error Error. Unable to find path: Screenshot 2023-09-12 at 15 06 40

Craft CMS version

3.7.16

Plugin version

2.2.1

Multi-site?

No

Additional context

No response

engram-design commented 1 year ago

Are you able to confirm what volume filesystem you're using? Local, S3 or other?

jamie-s-white commented 1 year ago

S3

jamie-s-white commented 1 year ago

This also happens when I just click save on an image that has already been uploaded.

I have done a bit of additional debugging on this, and I can see in:

src/services/Service.php

We have:

    public function beforeHandleAssetFile(AssetEvent $event)
    {
        $asset = $event->sender;
        $filename = $asset->filename;
        $path = $asset->tempFilePath;

When this bug occurs, $asset->tempFilePath is NULL.

Evidently it has other file information, such as $asset->filename, which is correctly set.

When we upload a fresh file, $path returns:

/var/www/example.com/releases/63/storage/runtime/temp/rc365084d3fe1c347.79901316.jpg

engram-design commented 1 year ago

Should be fixed for the next release. To get this early, run composer require verbb/image-resizer:"dev-craft-3 as 2.2.1".

jamie-s-white commented 1 year ago

Hi,

Now when we save a file, we get the error:

Could not open create the stream for “test.jpg”

(Where test.jpg is the name of the file).

From line 200 of vendor/craftcms/cms/src/base/FlysystemVolume.php

engram-design commented 1 year ago

Hmm, so that must be a result of $asset->getImageTransformSourcePath() which is supposed fetch the local copy of the asset for remote volumes. Can I ask what your S3 volume settings are?

jamie-s-white commented 1 year ago

Name: Files Handle: Files Assets in this volume have public URLs: true Subfolder: None Make uploads public: true Attempt to set the focal point automatically?: False Cache duration: 1 day CloudFront Distribution ID: Set CloudFront Path Prefix: Not set

Please let me know if you need any more information

engram-design commented 1 year ago

Looks identical to mine! I'll keep digging to try and replicate this.

jamie-s-white commented 1 year ago

Let me know if admin access to our staging environment might help, and I'll see if I can get that.

Also keep in mind that we are on Craft 3.7.16, in case that makes a difference. I'm not sure this client has the budget to update to the latest 3.9.x version. We are however using the latest version of the craftcms/aws-s3 plugin.

engram-design commented 1 year ago

That might be useful, and best to get in touch via support@verbb.io. I have been testing on Craft 3.9 as I wasn't under the impression it'd make a difference as there haven't been massive changes between those. But I'll spin up a site just in case.

jamie-s-white commented 1 year ago

Thank you! I have put in a request to grant you access, but we won't get that until next week. I will reach out to support@verbb.io when I know more.

jamie-s-white commented 1 year ago

I have now been pulled from this job due to lack of budget to take this further forward, so I will not be able to assist any further with this bug report. We have decided to resize the images manually instead of using this plugin, apologies.

jamie-s-white commented 1 year ago

I will also add that we are seeing this issue on at least one other of our projects however, and whenever we see the issue, we get the same result:

Could not open create the stream for “test.jpg”

engram-design commented 1 year ago

Thanks for the update, and sorry we haven't been able to get to the bottom of it. I'll keep at it on my end. I did test out on Craft 3.7 specifically, just in case that was a factor, but wasn't able to reproduce it.