craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 627 forks source link

[3.x]: Image transform 500 error on frontend and admin after moving site - Google Cloud Storage #12115

Closed seanjessen closed 1 year ago

seanjessen commented 1 year ago

What happened?

Description

Image transforms are returning a 500 error on frontend and also admin panel after moving a site from production environment to dev/staging environment. Google Cloud Storage is being used as the Asset volume.

Steps to reproduce

  1. Try to view assets in the admin panel or retrieve an image transform on the frontend using getUrl() with parameters passed in.

Expected behavior

Image transform URL should be returned.

Actual behavior

The following 500 error messages appear:

Image transform cannot be created.

Caused by: Asset Transform Error – craft\errors\AssetTransformException
Failed to generate transform with id of [x]

Caused by: Invalid Argument – Control character error, possibly incorrectly encoded

Craft CMS version

3.7

brianjhanson commented 1 year ago

It sounds like there might be an invalid character in your file names. Can you post a full stack trace from the logs?

seanjessen commented 1 year ago

@brianjhanson Please see stack trace below:

Next yii\web\ServerErrorHttpException: Image transform cannot be created. in /vendor/craftcms/cms/src/controllers/AssetsController.php:1157
Stack trace:
#0 [internal function]: craft\controllers\AssetsController->actionGenerateTransform(4)
#1 /vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#2 /vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#3 /vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('generate-transf...', Array)
#4 /vendor/craftcms/cms/src/web/Application.php(293): yii\base\Module->runAction('assets/generate...', Array)
#5 /vendor/craftcms/cms/src/web/Application.php(602): craft\web\Application->runAction('assets/generate...', Array)
#6 /vendor/craftcms/cms/src/web/Application.php(272): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#7 /vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#8 /web/index.php(21): yii\base\Application->run()
#9 /Users/xxx/.composer/vendor/laravel/valet/server.php(234): require('/Users/xxx...')
#10 {main}
brianjhanson commented 1 year ago

Hm, not much useful in there. Is this happening to every image? Or specific images? If it's happening on specific images, is there anything different about them (same filetype, special characters in the filename, etc.)?

When you say "after moving site", did you move the site to a new server (keeping the asset storage the same between servers)? Or recently move the assets over to Google Cloud from another service?

seanjessen commented 1 year ago

Yes this is happening to every image where transform parameters are passed into getUrl() on the frontend and also thumbnail transforms in the backend. If no parameters are passed into getUrl() on the frontend the images do get returned.

It was after creating a local development copy using valet that this occurs but it also occurs on a separate staging environment as well. Just the live site functions as it's supposed too. As far as I'm aware the assets have always been hosted on Google Cloud.

brianjhanson commented 1 year ago

Very odd. If the live site is working it sounds like an environmental issue vs. one directly with Craft. Did you double check that your credentials file is correct and that the plugin is pointed to the correct path?

seanjessen commented 1 year ago

Yes I checked both of those and the error still persists. It also occurs on image upload through the admin panel specifically with this error returned: Control character error, possibly incorrectly encoded

brianjhanson commented 1 year ago

Any chance there's a \n in your credentials somewhere? If so, can you make sure those are properly escaped?

seanjessen commented 1 year ago

@brandonkelly there was indeed an unescaped character in one of the environment variables. Thanks for your help!

brandonkelly commented 1 year ago

Good guess @brianjhanson!